I’m working on something new: an easy to set up Rails 5.1 development environment in Docker, configured via docker-compose. I’m maintaining a template for this on GitHub here:michiels/rails-docker-compose. Follow the README there for instructionson setting it up on your app.
Why am I doing this? I’d like all members in our team atFirmhouse to not have to think about local dependencies anymore when working on one of the many apps we develop. Getting set up with an app should be a matter of seconds.
Having a development environment per app also helps cleaning out any databases and Sidekiq queues and gem interdepencies. So you always have fresh and clean environment and you don’t have to recompile Ruby for each differeing version on your workstation.
I want to maintain the repository so it always supports a Rails development environment for:
- Latest Ruby on Rails
- Latest Ruby version
- Redis (for Sidekiq)
- RubyGems for installing gems (standard Rails)
- Yarn for installing JS dependencies (standard Rails)
- System tests with headless Chrome
You can read more detailed instructions in the README, but here’s the gist:
First, you copy over the Dockerfile, docker-compose.yml file and slightly modify your database.yml and docker-compose.yml.
Then, you set up the app’s database via:
$ docker-compose run --rm web rails db:setup
Finally, it’s super easy to start a local Rails development environment:
$ docker-compose up
Browse to http://localhost:3000/ and your app is up and running with Rails, PostgreSQL, Redis, and Sidekiq.
Bonus hint: Keep a local development session open for generating controllers and models, and running migrations and tests. For example:
$ bin/devconsole # rails g controller homepage # rails db:migrate # rails test # rails test:system
I’d love to see this set up work in your app. Let me know if it works out or what doesn’t.