Introducing a Rails 5.1 development environment via Docker

    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 instructions on setting it up on your app.


    Why am I doing this? I’d like all members in our team at Firmhouse 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.

    What it contains:

    I want to maintain the repository so it always supports a Rails development environment for:

    • Latest Ruby on Rails
    • Latest Ruby version
    • PostgreSQL
    • Redis (for Sidekiq)
    • RubyGems for installing gems (standard Rails)
    • Yarn for installing JS dependencies (standard Rails)
    • System tests with headless Chrome

    How does it work for your app?

    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

    Try it, please!

    I’d love to see this set up work in your app. Let me know if it works out or what doesn’t.

    Michiel Sikkes

    Michiel Sikkes

    Hi, I'm Michiel Sikkes. I'm the co-founder and CTO at Firmhouse, a SaaS platform that enables you to launch and grow subscription and product-as-a-service businesses.

    The Netherlands