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 :
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 !
git clone git@github.com:philou/rubybox.git
cd rubybox
docker-compose run rubybox
Leave a comment