Committing a modified container

As part of my project to build a container environment for a Ruby on RaiIs application I built a Dockerfile which would download and build a copy of ruby.

At the best of times this is a lengthy process but on a Raspberry Pi t takes an absolute age and it simply wouldn’t be practical to include as a deployment step for a Rails app.

So the way forward is run an interactive container from an image,

# docker run --rm -t -i resin/rpi-raspbian bash

And then run the Ruby build steps

# apt-get update
# apt-get install curl
# curl -L https://get.rvm.io | bash -s stable --ruby
... wait for several hours while Ruby builds ...
# source /usr/local/rvm/scripts/rvm
# rvm default
# ruby -v

The build takes so long that to prevent the connection dropping due to inactivity, I found it necessary to CTRL-Z the build and use ‘bg’ to run it in the background while running ‘top -d 2’ to keep the SSH traffic flowing.

Now, to avoid losing these changes and to be able to deploy future containers wth Ruby already installed we have a couple of options: 1) commit the container changes to a new image; 2) export the container filesystem to a tarball (to be imported elsewhere).

# docker ps
 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
 c395a08f285f 96ba3e6eec3d "bash" 7 hours ago Up 7 hours angry_jang
 # docker commit -a "Image Maintainer <maintainer@gmail.com>" -m "resin rpi-raspbian extended to include rvm and ruby 2.2.1" -p c395a08f285f

This is again quite a time consuming operation, but we can see the outcome with,

$ docker images
 REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
   96ba3e6eec3d 2 hours ago 665.9 MB

(We didn’t include a repository and tag with the commit). Notice also that the image size is a lot bigger than many of the others: the image includes lots of packages required to compile code which is likely to be needed when installing gems that use a native build (e.g., mysql2).

Anyway, the proof of the pudding comes when we deploy a container from the new image,

docker run --rm -t -i 96ba3e6eec3d bash
root@c395a08f285f:/# source /usr/local/rvm/scripts/rvm
root@c395a08f285f:/# rvm default
root@c395a08f285f:/# ruby -v
ruby 2.2.1p85 (2015-02-26 revision 49769) [armv6l-linux-eabihf]

So we have something usable for now and we can look at getting Apache and Phusion passenger running as well.

Running an export is simply a matter of the following,

docker export eb62f3daf840 > projects/docker/ruby-arm.tarls -l projects/docker/ruby-arm.tar
-rw-r--r-- 1 root root 681940992 Jun 1 22:50 projects/docker/ruby-arm.tar

I’m beginning to see why Docker is gaining so much ground at the moment.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s