A collection of computer systems and programming tips that you may find useful.
 
Brought to you by Craic Computing LLC, a bioinformatics consulting company.

Friday, September 19, 2014

Installing Ruby in Docker Images

Docker is a great way to package applications with all their dependent libraries etc and then deploy them easily on various hosts. It builds on tools like Vagrant.

I am interested in using it to package Ruby applications built with Sinatra or Rails.

The preferred way to build a Docker Image is to write a Dockerfile that contains instructions that load an operating system, installs system packages, copies user code, etc.

I am building my Images on top of Ubuntu 14.04, the current Ubuntu Linux release. A problem with most of the Linux distributions is that the packages that install Ruby are often one or two releases behind. In this case the packaged Ruby is 1.9.3 and the current release if 2.1.2. In many cases this would not be a problem but if you want the latest version then you have do a bit more work and, specifically, compile Ruby from source.

Once you have the Dockerfile working then this all happens very smoothly but it took me a while to get all the pieces working together. So I wrote up two versions of a minimal Sinatra application along with the Dockerfiles needed to get them to work.

The code is on Github at https://github.com/craic/docker_sinatra_examples

The Docker Images are on DockerHub at
https://registry.hub.docker.com/u/craic/docker_sinatra_example_1/
and
https://registry.hub.docker.com/u/craic/docker_sinatra_example_2/

The first example installs the packaged Ruby (1.9.3)
The second compiles and installs Ruby 2.1.2 from source.

I hope these examples help you get up to speed with Docker quickly.

No comments:

Archive of Tips