How to Prepare a New Ruby Env in 3 Minutes Using Docker

One or two weeks ago, I registered to the Paris Ruby Workshop Meetup and needed a Ruby env. I have been using Vagrant quite a lot to isolate my different dev envs from each other and from my main machine. As I’ve been digging more into Docker lately, I thought I’d simply use Docker and Docker Compose instead.

I turned out to be dead simple. All that is needed is a docker-compose.yml file to define the container, record the shared volume and set a bundle path inside it :

1
2
3
4
5
6
7
8
rubybox:
  image: ruby:2.3
  command: bash
  working_dir: /usr/src/app
  environment:
    BUNDLE_PATH: 'vendor/bundle'
  volumes:
    - '.:/usr/src/app'

Without the custom bundle path, bundled gems would be installed elsewhere in the container, and lost at every restart.

To use the Rubybox, just type docker-compose run rubybox and you’ll get a shell from within your ruby machine, where you can do everything you want.

In fact, I found the thing so useful, that I created the Rubybox git repo to simplify cloning and reusing. I’ve already cloned it at least 3 times since then !

1
2
3
git clone git@github.com:philou/rubybox.git
cd rubybox
docker-compose run rubybox

Comments