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
docker-compose upto 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
DOCKERFILEis 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
- Copy the three config files to the root folder of an existing Rails project. Make
chmod +x run.sh.
- Edit your development database settings to connect to Postgres at host
postgres, password is an empty string.
- Spin it up with
Your Rails app should be up and running at
http://localhost:3000. You should see someething like this:
Now a little about this configuration
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.