<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Alex Kleissner on Medium]]></title>
        <description><![CDATA[Stories by Alex Kleissner on Medium]]></description>
        <link>https://medium.com/@hex337?source=rss-9031facd04ac------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*v_KpscQMapdnpZJ7B6S-vQ.jpeg</url>
            <title>Stories by Alex Kleissner on Medium</title>
            <link>https://medium.com/@hex337?source=rss-9031facd04ac------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 09:48:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hex337/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Unifying Projects with Makefiles]]></title>
            <link>https://medium.com/chime-engineering/unifying-projects-with-makefiles-3f8db5372e6d?source=rss-9031facd04ac------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f8db5372e6d</guid>
            <category><![CDATA[developer-tools]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[developer-productivity]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Alex Kleissner]]></dc:creator>
            <pubDate>Fri, 21 Dec 2018 00:35:04 GMT</pubDate>
            <atom:updated>2018-12-21T00:55:49.181Z</atom:updated>
            <content:encoded><![CDATA[<p>At work, I end up spending time in many different projects. Some of these are similar, some are quite different. The tasks I want to do in them are usually the same: set up the project, initialize data, run tests, run the service.</p><p>Most companies don’t have a single stack anymore. You might have a few projects that use Elixir, and a few that use Rails (even those might have various versions of Rails). Sometimes my changes in a Rails project require me to run an Elixir service on my machine, but I have no clue how to set that up.</p><p>Take migrations as an example. Rails has you run ./bin/rails db:migrate and in Elixir I would do mix ecto.migrate. Both commands do the same thing, but have different syntaxes.</p><p>What I like is commonalities. My process for getting any project up and running should be the same, no matter which stack it’s on. The steps for setting up a repo should also be easy to understand and easy to learn from if I care to peek under the hood.</p><p>I ended up going with setting up a Makefile in each project at Chime. In the above example, I should just be able to make migrate in either project, and presto! My project does the right thing.</p><h3>But… Why make?</h3><p>I know, I know! Make is that thing you used forever ago to coordinate how your C++ files compiled to avoid linking errors. Or at least, I think that’s what I used to use them for. We’re going to use them as a glorified command line execution system — something far more benign.</p><p>Make is available in pretty much every linux environment. It’s straight forward, and it’s easy to debug. It doesn’t have a ton of bells and whistles, but that means it will always just work.</p><p>When a developer clones a new repo at Chime, they can take a quick glance at the Makefile and know what has to happen (also, keeping README’s up to date is key). I can run make build, then make setup_db followed by a make test and it won’t matter if it’s Ruby, Elixir, or some other crazy stack.</p><p>The best part? You can actually group make commands into similar files and then include them in your main Makefile. We use this to DRY up common make commands that relate to our mysql instance, as well as other things like bringing up and down docker-compose environments. You can do that by adding this to your Makefile:</p><p>include Makefile.common</p><p>You could have things like Makefile.rails and Makefile.phoenix to dry things up even more.</p><h3>Tips &amp; Tricks</h3><p>Make it self-documenting! One of my favorite parts about this, is adding the following to my top level common Makefile:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e49c6a06b1c0c047abc5395526dead09/href">https://medium.com/media/e49c6a06b1c0c047abc5395526dead09/href</a></iframe><p>This will pull any comments that start with #: out and display them nicely for anyone who’s looking at what’s available.</p><p>You can also use environment variables to pass parameters. To see a full example, here’s one that I have set up for a <a href="https://github.com/hex337/alex-koin/blob/master/Makefile">personal project</a> of mine:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c35f31a4f04b7eb4f328985775251d8/href">https://medium.com/media/9c35f31a4f04b7eb4f328985775251d8/href</a></iframe><p>The end result of running make help looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*OiN7ua2WIN-yKkdiHtfbYg.png" /><figcaption>Documentation is good.</figcaption></figure><p>Do you have some tips or tricks you can share? I’d love to hear them!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f8db5372e6d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/chime-engineering/unifying-projects-with-makefiles-3f8db5372e6d">Unifying Projects with Makefiles</a> was originally published in <a href="https://medium.com/chime-engineering">Breaking the Bank</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Planning an Internal Elixir Hackathon]]></title>
            <link>https://medium.com/chime-engineering/planning-an-internal-elixir-hackathon-2d0a6683bde8?source=rss-9031facd04ac------2</link>
            <guid isPermaLink="false">https://medium.com/p/2d0a6683bde8</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[learning-to-code]]></category>
            <category><![CDATA[elixir]]></category>
            <dc:creator><![CDATA[Alex Kleissner]]></dc:creator>
            <pubDate>Tue, 02 Oct 2018 18:58:56 GMT</pubDate>
            <atom:updated>2018-10-02T22:53:57.119Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1suRrl8bDbHhTEa63dN38g.jpeg" /><figcaption>A world of possibilities when playing with a new programming language. Photo by Alex Kleissner</figcaption></figure><p>I’ll cover the following topics, feel free to jump around to the bits that speak to you:</p><ol><li><strong>Background</strong></li><li><strong>Initial Proposal</strong></li><li><strong>Prep Work</strong></li><li><strong>Day-of</strong></li><li><strong>What I Learned</strong></li></ol><p>In late 2017, I found myself in a position to look for a new job, which meant asking myself what I wanted. Did I want to keep pushing down the Python route? Maybe go back to Ruby? I had been playing around with React and thought it was pretty amazing, but I’ve always been more of a back end kind of person.</p><p>I ended up focusing on Ruby because I felt I had a strong grasp on it and generally liked working in it. About two weeks into the job search, I had a ping from a recruiter asking if I would be interested in a job that was using Elixir. At first I thought, “No way, I’m wanting to get back into Ruby and don’t need to get side tracked. Besides, I tried Go, and it was ok, but not my jam.”</p><p>Fast-forward about two more weeks and I’m trying to do some of my interview take-home questions in Elixir in an attempt to force myself to learn it. Functional programming? Heck yes. Immutable data? Be still my beating heart. Parallel processing and async I/O? It was like falling in love all over again. There was just one tiny hiccup: I accepted a job at <a href="https://www.chimebank.com/">Chime</a> where the back end is all Ruby on Rails.</p><p>Luckily I had already talked about Elixir in my interview, and the overall engineering vibe at Chime is one of “if it makes sense and we can present a business case for it, let’s try it!” Before I could really push any kind of Elixir-based project, I needed to get people excited and interested in learning a new language and framework.</p><h3>Making the Initial Proposal</h3><p>At past jobs, I’ve participated in learning groups when a adopting a new technology or framework. These can work well, but one <strong>large problem is that the “extra” work of learning usually gets offloaded to non-work hours</strong>. If Chime was going to be serious about trying out this new tech, I wanted us to put valuable work hours toward learning Elixir.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gCMtmkReqJFPOEqy" /><figcaption>“people sitting down near table with assorted laptop computers” by <a href="https://unsplash.com/@marvelous?utm_source=medium&amp;utm_medium=referral">Marvin Meyer</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I wrote up a quick one-page document to lay out the goals and budget requirements to set up a one-day off-site Elixir focused hackathon. I noted that the off-site part, while not necessary, was high priority for me. Pulling engineers out of the day-to-day would allow for a more focused space for learning and building. I can also now admit that getting the CTO to OK some budget for a breather room was also a bit of a litmus test on how seriously we were considering Elixir. I made sure to find a range of options for the breather to fit different budgets. If you will have more than 6 people, I would definitely suggest finding a space that has at least two physical rooms so that groups can collaborate without interfering with each other.</p><p>For the hackathon to be successful, I wanted other engineers to see where functional programming could be powerful. They should walk away from the day with a sense of accomplishment for having pushed out production-capable code. This meant that picking projects that would benefit from the underlying differences of Elixir was crucial to the hackathon’s success.</p><p>It took all of about 10 minutes for the CTO and VP of Eng to say “very yes” to the hackathon idea. I was pretty stoked, but now I also had to deliver on my ambitious plan.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*8JWfHe2OhnLyDUH1hjcs7g.gif" /><figcaption>Image via giphy.com</figcaption></figure><h3>Hackathon Prep Work</h3><p>I really wanted to focus on getting as much learning done as possible. I identified the following as the enablers of that:</p><ol><li>Focus only on Elixir and Phoenix work.</li><li>Remove as many setup issues as possible.</li><li>Pick the right projects.</li></ol><p>I encouraged people to do as much prep work as they could in the weeks leading up to the event. This included everything from “here’s some good learning resources to pick up the syntax”, to “here’s a dockerized project that you can start playing with”. The goal was to remove as much of the language basics learning time as possible.</p><p>For the hackathon itself, I took each of the potential projects and set up repos a week ahead of time with all the necessary set up to hit the ground running. Each project had a working <a href="https://medium.com/@hex337/setting-up-a-phoenix-1-3-4-project-with-docker-72f019c5954f">docker-compose</a> environment and a README with instructions on how to get the project running locally. Having this ready <strong>early</strong> also helped reduce setup time during the hackathon.</p><p>Picking the right projects was the hardest task. The scope had to be small enough that people could work on it and make progress in one day, and it had to be something that would leverage the power of Elixir. There’s no secret recipe here. I had never run something like this before, and I am far from an expert in Elixir and Phoenix. For our next hackathon, I’ll have a better idea of what our team can accomplish in one day, and which internal projects would benefit from the tech.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qqpSd5w9bOoTwvMh6pjiow.jpeg" /><figcaption>A clean workspace creates clean code. Photo by Alex Kleissner</figcaption></figure><p>The three projects I ended up going with:</p><ul><li>a <a href="https://graphql.org/">GraphQL</a> server</li><li>a background script processor job</li><li>common logging and stats tracking for Phoenix projects</li></ul><p>Why GraphQL? Outside of wanting to experiment with it for our apps, we also see it as more of an aggregation framework for our transition to <a href="https://en.wikipedia.org/wiki/Service-oriented_architecture">SOA</a>. Since GraphQL allows us to define reducers, we can farm out pieces of a query to multiple back end services and aggregate the results without forcing the front end app to hit multiple services. We can leverage the async I/O strengths of Elixir - in this case for any of the downstream services that take a while to respond (a common experience when dealing with moving money).</p><p>The last piece of the puzzle was matching people with shared project interest and Elixir skill levels. We’d work in pairs, each pair having one developer with more Elixir experience. This would help facilitate more knowledge sharing and learning.</p><h3>Day of Learnings</h3><p>With the Hackathon day upon us, we settled into the Breather we rented near the office. I gave a quick overview of the projects along with the first few steps that I thought people should tackle (I put these into GitHub issues, but we ended up not really using them since... GitHub issues).</p><p>The rest of the day was split into three, two-hour focused working sessions:</p><ul><li>First kick off the projects</li><li>Lunch break</li><li>Second focus sesssion</li><li>Show and Tell</li><li>Final session to wrap things up</li></ul><p>The two hour cadence seemed about right. More can get taxing when you’re learning something new, and less can prevent you from finishing anything.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ji6Avu-h6HXQQBh_PehJ0w.jpeg" /><figcaption>Morning working session, powered by coffee. Also # laptops &gt; # people? Photo by Alex Kleissner</figcaption></figure><p>One of my initial goals was to produce a production-ready piece of software in Elixir that we could deploy, or at least get to a deployable state with minimal follow-up effort. Turns out that was a lot more ambitious than I thought, and that ended up being my biggest frustration with the entire event. While we made some great progress on the projects, we did not have enough dev ops infrastructure in place to run any Elixir projects in any of our environments. We also didn’t get to a good deployable state for any of the three projects. Between initial language learning, and overall project context, everything I picked was far too ambitious to finish in one day.</p><p>In spite of those results, the day went well. The GraphQL service pulled a separate service in, validating that it could work as a proxy. Our background script jumped over the initial hurdles and had the inklings of some impressive performance improvements. We even have a <a href="https://hexdocs.pm/phoenix/plug.html">Plug</a> that we can use to do stats tracking for request durations in Phoenix projects.</p><h3>Post-Event Learnings</h3><p>I set up a quick type form feedback survey for people to fill out after the event to see what went well or didn’t go well. The interesting learnings:</p><ol><li>Having a space with two rooms was great, but the lack of monitors and more collaborative work stations wasn’t great.</li><li>Being explicit about ensuring all participants get work time to prep would help reduce frustrations (mostly around me feeling like the time wasn’t used to its maximum potential).</li><li>Taking time away from the normal office was a big win.</li><li>Sharing what people accomplished and learned half way through was really helpful for everyone.</li><li>Finding the right project(s) is hard and you might not nail it.</li></ol><p>I wanted to spark interest in Elixir and highlight what we could do with it. I think I definitely sparked interest, but fell short on really highlighting where Elixir and Ruby differ. Luckily, there’s enough interest that we’re continuing to have mini-hackathons to build on the work we started. We even have a few key services slated for development on our one year road map that will use Elixir, a direct result of the learnings from the off-site.</p><p>Do you want to run a hackathon for your company? Do you have other ideas around how to help a company transition to a new technology or framework? I’d love to hear what’s worked for you or your team.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d0a6683bde8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/chime-engineering/planning-an-internal-elixir-hackathon-2d0a6683bde8">Planning an Internal Elixir Hackathon</a> was originally published in <a href="https://medium.com/chime-engineering">Breaking the Bank</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting up a Phoenix 1.3.4 Project With Docker]]></title>
            <link>https://medium.com/@hex337/setting-up-a-phoenix-1-3-4-project-with-docker-72f019c5954f?source=rss-9031facd04ac------2</link>
            <guid isPermaLink="false">https://medium.com/p/72f019c5954f</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[phoenix-framework]]></category>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Alex Kleissner]]></dc:creator>
            <pubDate>Fri, 17 Aug 2018 04:08:39 GMT</pubDate>
            <atom:updated>2019-04-26T19:11:58.556Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U-x6qEWMi0r7B0_oXI6dEQ.jpeg" /><figcaption>All that open sky is your computer’s hard drive without 1000 versions of different languages installed on it.</figcaption></figure><p>As a follow up to my <a href="https://medium.com/@hex337/running-a-phoenix-1-3-project-with-docker-compose-d82ab55e43cf">original post</a>, I wanted to create a cleaner system for getting phoenix projects up and running.</p><p>We’ll set up a container that’s running <a href="https://phoenixframework.org/">Phoenix 1.3.4</a> with <a href="https://elixir-lang.org/">Elixir 1.6</a>. It’ll be backed by a postgres database. We’ll do all of this <strong><em>without installing anything on our local machine</em></strong>.</p><p>Create a new directory for your project, we’ll call this phoenix-api for now.</p><pre>$ mkdir ~/projects/phoenix-api</pre><h3>Dockerfile</h3><p>We’ll go ahead and set up a Dockerfile to build a container, which we can then use to run the commands we&#39;ll need to initialize the Phoenix project.</p><pre>FROM elixir:1.6<br>MAINTAINER <a href="/service/mailto:you@gmail.com">you@gmail.com</a></pre><pre>ENV HOME=/usr/src/phoenix-api</pre><pre>RUN apt-get update &amp;&amp; apt-get upgrade -y &amp;&amp; \<br>    apt-get install -y inotify-tools build-essential postgresql-client &amp;&amp; \<br>    mix local.rebar --force &amp;&amp; \<br>    mix local.hex --force</pre><pre># Uncomment if you need to use a front-end<br>#RUN apt-get install -y sudo wget curl zip unzip</pre><pre># If you plan to run a web interface, you&#39;ll want to use the following:<br>#RUN curl -sL <a href="https://deb.nodesource.com/setup_9.x">https://deb.nodesource.com/setup_9.x</a> | sudo -E bash - &amp;&amp; apt-get install -y nodejs</pre><pre>ADD . $HOME</pre><pre>WORKDIR $HOME<br>EXPOSE 4000</pre><p>With this done, we can run docker build -t phoenix-api:latest . and get a container for this Dockerfile with the phoenix-api:latest tag.</p><h3>Compose That API</h3><p>Next up, we’ll set up our bare bones compose file.</p><p>We have two containers that we need, our api server and our database.</p><p>Lets create our docker-compose.yml file:</p><pre>version: &#39;3&#39;</pre><pre>services:<br>  api:<br>    build: .<br>    ports:<br>      - &quot;4000:4000&quot;<br>    volumes:<br>      - .:/usr/src/phoenix-api<br>    depends_on:<br>      - db</pre><pre>  db:<br>    image: &quot;postgres:9.6.3&quot;<br>    volumes:<br>      - db-data:/var/lib/postgresql/data</pre><pre>volumes:<br>  db-data:</pre><p>We can now run a compose build with</p><p>docker-compose build</p><p>Once that builds, we need to get a bash prompt on the container with</p><p>docker-compose run --rm api bash</p><p>The --rm makes sure that we dispose of our container when we&#39;re done, since we don&#39;t need it to stick around. We just want to create a new project and then drop it.</p><p>With a bash prompt, we can install the phx_new mix task.</p><pre>mix archive.install --force <a href="https://github.com/phoenixframework/archives/raw/master/phx_new.ez">https://github.com/phoenixframework/archives/raw/master/phx_new.ez</a><br>mix phx.new --no-brunch --no-html --app phoenix_api ../phoenix-api</pre><p>This will then ask you if you are sure since the phoenix-api folder already exists. Say Yes to that and for installing dependencies. I&#39;m sure some people will complain that this circumvents the whole umbrella project thing, but I find that this is what I want most of the time for my own projects. Using the relative directory and having it bound to your local dir prevents the nesting from happening.</p><p>Once all that finishes, let’s get our dependencies installed and then exit out of the container.</p><pre>mix deps.get<br>... lots of stuff here ...<br>exit</pre><h3>Setting up the Database</h3><p>We’ll have to tell Phoenix where our dockerized database lives, so boot up your favorite editor for config/dev.ex.</p><p>Find the part that looks like this and change the hostname field to use the name of the db container.</p><pre># Configure your database<br>config :phoenix_aptlist, PhoenixAptlist.Repo,<br>  adapter: Ecto.Adapters.Postgres,<br>  username: &quot;postgres&quot;,<br>  password: &quot;postgres&quot;,<br>  database: &quot;phoenix_api_dev&quot;,<br>  hostname: &quot;db&quot;,<br>  port: 5432,<br>  pool_size: 10</pre><p>To now create the table, lets run docker-compose run --rm api mix ecto.create. Since the api container depends on the db container, that will start up before the api container spins up.</p><h3>Setting up the Entryfile</h3><p>Next up, we’ll want to modify our Dockerfile to add an entry file that will boot up our Phoenix service when the container starts.</p><p>Open up the Dockerfile and edit the bottom part to look like this:</p><pre>RUN apt-get update &amp;&amp; ...</pre><pre>COPY ./docker-entrypoint.sh /<br>RUN chmod +x /docker-entrypoint.sh<br>ENTRYPOINT [&quot;/docker-entrypoint.sh&quot;]</pre><pre>ADD . $HOME</pre><p>The docker-entrypoint.sh is what we care about. But... what does that look like?</p><p>Probably something like this (<strong>NOTE</strong>: you have to have your database container name in the -h flag for this to work properly):</p><pre>#!/bin/bash</pre><pre># fail if we error out<br>set -e</pre><pre># Wait for database to come up<br>until psql -h db -U &quot;postgres&quot; -c &#39;\q&#39; 2&gt;/dev/null; do<br>  &gt;&amp;2 echo &quot;Postgres is unavailable - sleeping&quot;<br>  sleep 1<br>done</pre><pre># Ensure we have the basics...<br>mix local.hex --force<br>mix local.rebar --force</pre><pre>mix phx.server</pre><p>We need to allow our entrypoint to be executable:</p><pre>chmod +x docker-entrypoint.sh</pre><h3>Putting it all Together</h3><p>Build and run the containers:</p><pre>docker-compose build<br>docker-compose up -d</pre><p>We can see when the server is ready by following the logs:</p><pre>docker-compose logs -tf api</pre><p>Once everything is running, you can see an error page at <a href="http://localhost:4000/">http://localhost:4000</a>. Now you just have to add some API routes.</p><p>Congrats on getting a Phoenix project started <strong><em>without installing</em></strong> any Elixir on your computer!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=72f019c5954f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Running a Phoenix 1.3 project with docker-compose]]></title>
            <link>https://medium.com/@hex337/running-a-phoenix-1-3-project-with-docker-compose-d82ab55e43cf?source=rss-9031facd04ac------2</link>
            <guid isPermaLink="false">https://medium.com/p/d82ab55e43cf</guid>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[phoenix-framework]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Alex Kleissner]]></dc:creator>
            <pubDate>Mon, 20 Nov 2017 20:19:11 GMT</pubDate>
            <atom:updated>2018-06-01T21:54:13.123Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nTqtWMyjsZrmhzdfN7g-BQ.jpeg" /><figcaption>A clean development environment should be as calming as the desert.</figcaption></figure><p>I’ve been looking at job postings, and saw that Elixir has picked up a fair bit of traction. It’s not hard to see why, syntax similar to Ruby, functional constructs like Scala, and running on top of the Erlang VM… sounds like a whole lot of winning in the rush to do more with APIs and use fewer resources.</p><p>Given the prevalence of docker for development environments, and the prospect of not having to locally install any of the Elixir/Erlang cruft on my local machine, I set out to do a small project using <a href="http://phoenixframework.org/">Phoenix 1.3</a> in Docker. A lot of the information I found online dealt with Phoenix 1.2 or older. Hopefully this will help others save 15–90 minues of head scratching if they followed a different tutorial.</p><h3>Setting up the initial Dockerfile.</h3><p>We will be going with the following software versions:</p><ul><li>Elixir 1.5</li><li>Phoenix 1.3</li><li>PostgreSQL 9.6.3</li></ul><p>Go to your base project directory, and fire up your editor of choice. We’ll be creating a Dockerfile that looks like this:</p><pre>FROM elixir:1.5<br>MAINTAINER YOUR_NAME_HERE</pre><pre>RUN apt-get update &amp;&amp; apt-get install --yes postgresql-client</pre><pre>ADD . /app</pre><pre>RUN mix local.hex --force<br>RUN mix archive.install --force <a href="https://github.com/phoenixframework/archives/raw/master/phx_new.ez">https://github.com/phoenixframework/archives/raw/master/phx_new.ez</a></pre><pre>WORKDIR /app<br>EXPOSE 4000<br>CMD [&quot;./run.sh&quot;]</pre><p>There are a few important things in this. First, we’re adding the postgresql client, which will allow Phoenix to nicely talk to the database. The second, is the bit after the local.hex mix call, which installs the Phoenix commands on the container. The last bit, is a little weird, instead of running CMD [&quot;mix&quot;, &quot;phx.server&quot;] as our entry command, we’re instead going to run a bash file to bring up the server. I’ll explain why, after we’ve created our new Phoenix project. Before we run this, let’s set up our docker-compose file so that we can get used to running commands through that.</p><h3>Setting up your docker-compose file:</h3><p>We know that we’ll want a database running that the Phoenix project can talk to, so we set up a simple docker-compose.yml file. Boot up that editor of yours and create the following file:</p><pre>version: &#39;3&#39;</pre><pre>services:<br>  web:<br>    build: .<br>    ports:<br>      - &quot;4000:4000&quot;<br>    volumes:<br>      - .:/app<br>    depends_on:<br>      - db</pre><pre>  db:<br>    image: &quot;postgres:9.6.3&quot;</pre><p>This sets up two services, web and db. Web is our Phoenix application, and db is… well our database. Now that we have that squared away, lets initialize our Phoenix application.</p><h3>Setting up your Phoenix project:</h3><p>From your project directory, run a command to initalize the project:</p><pre>$ docker-compose run --rm web mix phx.new --no-brunch --no-html YOUR_PROJECT_NAME</pre><p>You might want to use different options when creating your project, in this case it will create a project without the javascript and HTML components. Useful if you’re creating an API service. This will generate a whole bunch of files, and since we’re using a shared volume, those files will appear on our local machine, but we never had to install Erlang, Elixir, or Phoenix!</p><p>Let’s connect the database through the config, set up our run.sh file and boot up the project. In your editor, open up config/dev.exs. Find the database configuration part, and modify it to look something like this:</p><pre># Configure your database<br>config :phoenix_aptlist, PhoenixAptlist.Repo,<br>  adapter: Ecto.Adapters.Postgres,<br>  username: &quot;postgres&quot;,<br>  password: &quot;postgres&quot;,<br>  database: &quot;YOUR_DB_NAME&quot;,<br>  hostname: &quot;db&quot;,<br>  port: 5432,<br>  pool_size: 10</pre><p>The hostname needs to match the “name” of the service we defined in the docker-compose.yml file, in this case, db.</p><h3>Putting it all together:</h3><p>Remember that run.sh command that we’re using instead of just running the server directly? The main reason for that is our postgres instance. When postgres boots up, it does a fast shutdown and then reboots again with the non-root user. I tried to get around this using the heartbeat functionality in docker-compose, but never had success with it. For now, the annoying workaround is adding a sleep before we boot up the server. Create the run.sh file, looking something like this:</p><pre>#!/bin/sh<br># With help from <a href="https://dogsnog.blog/2018/02/02/a-docker-based-development-environment-for-elixirphoenix/">https://dogsnog.blog/2018/02/02/a-docker-based-development-environment-for-elixirphoenix/</a></pre><pre>set -e</pre><pre># Wait for Postgres to become available.<br>until psql -h db -U &quot;postgres&quot; -c &#39;\q&#39; 2&gt;/dev/null; do<br>  &gt;&amp;2 echo &quot;Postgres is unavailable - sleeping&quot;<br>  sleep 1<br>done<br><br>mix ecto.create<br>mix ecto.migrate<br>mix phx.server</pre><p>Make sure that you add executable properties to your run.sh file.</p><pre>chmod +x run.sh</pre><p>Now, we can boot up all of our services with:</p><pre>docker-compose build<br>docker-compose up</pre><p>You should see a bunch of output that initializes the database and runs migrations (which we shouldn’t have any). Your Phoenix server should now accept connections. If you ended up doing a basic server with no html, you can test if it’s up by going to the root page <a href="http://localhost:4000/">http://localhost:4000</a> and you should see something about a route not existing.</p><p>Congrats! Now it’s time to build out your API or application.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d82ab55e43cf" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>