Using Docker for RubyGems projects
Posted on by Gentaro "hibariya" Terada
Sometimes I want to create a new gem or modify existing gems to extend/fix them. However, I do not want to install tons of additional development tools on my host machine for that. Recently, I created a shell script which creates an instant development environment on Docker for that.
#!/bin/sh -e
exec docker run --rm -it \
--workdir=/work \
-v $(pwd):/work \
-v=$HOME/.gitconfig:/root/.gitconfig \
-v=$HOME/.ssh:/root/.ssh \
-v=$HOME/.gem/credentials:/root/.gem/credentials \
ruby:${VERSION:-2.6.5} \
/bin/bash "$@"
This is a deadly-simple wrapper for docker command to run a ruby container mounting minimum-required files. Just put this file under a directory whatever it is in $PATH
list (For example, /usr/local/bin/rubyshell
) and run rubyshell
in a Ruby project. Then I can do Ruby things such as bundle
.
It is such a cheap environment but handy enough because I just want to run only a few ruby/bundler commands so far.