Setting up development environments has always been a huge pain for software teams. Not only is it time-consuming, but it’s also one of the major roadblocks in onboarding new team members.

Tools have improved a lot in the past few years. We’ve got great package managers such as HomeBrew, one-click installers as RailsInstaller, and even full-blown virtualized environments as Vagrant. And I’m sure, you’ve heard of Docker.

I noticed a lot of developers think Docker is mostly for production deployments and completely overlook its advantages for automating development workflows.

At Dockbit, we have a Docker Compose based development environment, and it has worked great so far. In this post, I’d like to share how we’re using Docker for development purposes and things we had to do in order to get it nearly as smooth as a “native” development experience.

Background

Our Web application is based on Ruby on Rails with PostgreSQL database, Sidekiq with Redis for background jobs and Hashicorp Vault for securing sensitive data. Check out our detailed tech stack on StackShare.

That’s already quite some moving parts and setting up each of them separately, every time a new person joins our team is a complete waste of time. Ideally, we would want to execute just one command to provision our complete development environment with all the bells and whistles, which would also be as close as possible to production. So, please, no shortcuts with SQLite, in-memory stores, nor custom “dev-only” configuration.

Docker Toolbox and Docker for Mac

It’s becoming really easy to install Docker environments locally and there are a number of ways to run it. If you are on Mac, I recommend using Docker for Mac to get started. It runs as a native Mac application and uses xhyve to virtualize the Docker environment, so it’s much more robust.

For our setup though, we’ve sticked with the Docker Toolbox, since some of our services listen on the network, rather than the socket. There are ways to get it working with socat, but we haven’t looked into that yet (if you happen to have experience with it, please let us know).

Internally, Docker Toolbox runs a docker-machine, which supports a number of virtualized environments, including VirtualBox.

Setting things up

Assuming you’ve got Docker installed and the docker command runs without problems in your terminal, it’s now only about creating a couple of files in the root of your app directory: Dockerfile and docker-compose.yml .

We have created a helper script named ./bin/dockbox that we use to bootstrap development environment and generate a “personal” Dockerfile . This allows us to make modifications to the Dockerfile (like user’s home directory) and experiment with new infrastructure components.

Finally, we have a tiny wrapper named ./bin/run to help us run one-off Rails commands inside the container without the need to type docker-compose web run all the time.

The setup described above has enabled any new developer joining our team to have things running locally with a single command in under 10 mins. Take a look, isn’t it cool?! 😜

Now, when things are up and running, our developers can run one-off Rails commands or manage backing services with the Docker Compose:

bin/run rails db:seed

bin/run bundle

docker-compose logs -f

You can find the scripts that power our development environment in this GitHub Gist. Feel free to leave your comments if you have any questions.