Docker image installed multiple versions of ruby
This can generate Docker image which is installed multiple versions of ruby by rbenv.
The image is pushed at docker.io, tcnksm/rbenv, so you can use it soon.
$ docker pull tcnksm/rbenv
or in Dockerfile,
FROM tcnksm/rbenv
Dockerfile
I will describe this Dockerfile and how to edit it for your own image.
FROM base
MAINTAINER tcnksm "https://github.com/tcnksm"
# Install packages for building ruby
RUN apt-get update
RUN apt-get install -y --force-yes build-essential curl git
RUN apt-get install -y --force-yes zlib1g-dev libssl-dev libreadline-dev libyaml-dev libxml2-dev libxslt-dev
RUN apt-get clean
# Install rbenv and ruby-build
RUN git clone https://github.com/sstephenson/rbenv.git /root/.rbenv
RUN git clone https://github.com/sstephenson/ruby-build.git /root/.rbenv/plugins/ruby-build
RUN ./root/.rbenv/plugins/ruby-build/install.sh
ENV PATH /root/.rbenv/bin:$PATH
RUN echo 'eval "$(rbenv init -)"' >> /etc/profile.d/rbenv.sh # or /etc/profile
# Install multiple versions of ruby
ENV CONFIGURE_OPTS --disable-install-doc
ADD ./versions.txt /root/versions.txt
RUN xargs -L 1 rbenv install < /root/versions.txt
# Install Bundler for each version of ruby
RUN echo 'gem: --no-rdoc --no-ri' >> /.gemrc
RUN bash -l -c 'for v in $(cat /root/versions.txt); do rbenv global $v; gem install bundler; done'
Basically, this Dockerfile does what you do when you install multiple versions of ruby by yourself in Ubuntu environment.
- Pull the base ubuntu image from docker.io (
FROM base) - Install packages for building ruby (
RUN apt-get ...) - Clone rbenv
- Clone ruby-build
- Set environmental variable for rbenv (
ENV PATH /root/.rbenv/bin:$PATH) - Set bash login command to read rbenv setting (
RUN echo 'eval "$(rbenv init -)"' >> /etc/profile.d/rbenv.sh) - Add
versions.txtwhich is defined ruby version which you want to install - Install ruby with
rbenv install - Install bundler for each versions
If you want to install another version (this time, only 1.8.7, 1.9.3, 2.0.0), just edit version.txt.
Furthermore, if you want to install basic rubygems by Gemfile, add below,
ADD ./Gemfile /root/Gemfile
RUN bash -l -c 'cd /root/; for v in $(cat rubies.txt); do rbenv global $v; bundle install; done'
To build image,
docker build -t USERNAME/IMAGENAME .
To push it to docker.io,
docker login
docker push USERNAME/IMAGENAME
Reference
Written by tcnksm
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#