Config files for Ruby on Rails development using Docker
What you get
- One-line dev environment setup and launch:
- One easy-to-install dependency to get coding on a new computer: Docker. (Versus two complex ones when using Vagrant.)
- 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 Postgres startup delay.
- All the crappy little dependencies installed.
- No weird hacks.
- Tested with current Ruby and Rails as of 2018-02-02: Ruby 2.5.0, Rails 5.1.4
Tested on MacOS and Fedora Linux, because that's what I happen to use. This is my personal configuration that I use for client work and my own projects. It's the result of several late-night hours getting everything working!
How to Dockerize your Rails app
- Install Docker somehow. I use Docker for Mac.
- Copy the three config files to an existing Rails project. Make
chmod +x run.sh.
- Edit your development database settings to connect to Postgres at host
postgres, password empty string.
- Spin it up with
Tests can be run in the container like so:
docker-compose exec web rspec
I create an alias
run so that I just do:
Or use Spring inside Docker the cheap and easy way:
docker-compose exec web bash bin/rspec
...then leave that session open and re-run the tests with a fast Spring boot up: