Setting up a Docker dev environment for Elixir+Phoenix

Benefits

  • One-line setup and bootup: docker-compose up. It creates the database, does the Dialyzer pre-work (if the project has Dialyxer installed), etc.
  • A true development-oriented config: Source code is mounted so that changes in the container appear on the host, and vice-versa.
  • Fast re-builds because the DOCKERFILE is written to help Docker cache the images.
  • Syncing with the Postgres startup delay.
  • All the crappy little dependencies installed.
  • No weird hacks.

Now the three files, followed by instructions and my comments (or jump straight to the GitHub Repo):

How to Dockerize a Phoenix app

  1. Copy the three config files to the root folder of an existing Phoenix project. Make run.sh executable, e.g.: chmod +x run.sh.
  2. Edit your development database settings to connect to Postgres at host db, username postgres, password is an empty string.
  3. Spin it up with docker-compose up.

The Phoenix app should be up and running at http://localhost:4000. Something like this:

Screen Shot 2018-02-02 at 2.01.43 AM

Now a little about this configuration

It’s the result of several hours spent fine-tuning it and going through the Docker file references. I wanted a “online-liner” container-based dev environment. To get this, I started with a Rails Docker config and got a boost from this excellent post by Alex Kleissner. He had the nice idea of a run.sh script to do some things like synchronize Phoenix and Postgres.

Also available as a GitHub repo. I have a very similar config for my Rails work as well.

Leave a Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s