A Docker dev config for Ruby on Rails

I use Docker for all my client work, and most of my personal projects too. I love it. It’s saved me a ton of money because it uses so much less RAM than Vagrant — what I had been using.

Benefits of this config

  • Just docker-compose up to set up and launch the dev environment (Yep, a one-liner like vagrant up – that’s the goal.)
  • One easy-to-install dependency to get coding on a new computer: Docker. (Versus two complex ones when using Vagrant.)
  • 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 right to the GitHub Repo.

How to Dockerize a Rails app

  1. Copy the three config files to the root folder of an existing Rails 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.

Your Rails app should be up and running at http://localhost:3000. You should see someething like this:

Screen Shot 2018-02-02 at 8.58.05 PM

Now a little about this configuration

It’s nearly identical to my Phoenix/Docker config, and so I’ve written a nearly identical blog post.

These files are 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; a Docker equivalent of vagrant up. To get this, I read a ton of example configs 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 startup and Postgres.

Also available as a GitHub repo.

2 thoughts on “A Docker dev config for Ruby on Rails

Comments are closed.