Sharing Docker containers

Over the past 2+ years I have been working as a sysadmin of a Linux network using bash scripts, Make files, etc. The most useful tools I have learnt so far is Chef for something called “configuration management” 🙂 In a nutshell, Chef is used to deploy the same configuration in multiple server in an iterative manner.

At this context I use Docker containers to test the “recipes” before deploying them in real machines. Sometimes I have some containers that I would like to share with other colleagues. Let’s see how to do it.

Use the Docker CLI save and load command to create a tar ball from a previously created image or use the Docker CLI import and export command for containers. Let’s start with a stop container and export it to a new tar ball:

$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
77d9619a7a71 ubuntu:14.04 “/bin/bash” 10 seconds ago Exited (0) 2 seconds ago high_

$ docker export 77d9619a7a71 > update.tar

You could of course commit this container as a new image locally but you could also use the Docker import command:

$ docker import – update < update.tar
157bcbb5fdfce0e7c10ef67ebdba737a491214708a5f266a3c74aa6b0cfde078
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
update latest 157bcbb5fdfc 8 seconds ago 188.1 MB

If you wanted to share this image with one of your collaborators you could upload a zip version of this tar ball on a webserver and let your collaborator download it and use the import command on his Docker host. If you would rather deal with images that you have already committed, you can use the load and save commands.

$ docker save -o update1.tar update
$ ls -l
total 385168
-rw-rw-r– 1 vagrant vagrant 197206528 Jan 13 14:13 update1.tar
-rw-rw-r– 1 vagrant vagrant 197200896 Jan 13 14:05 update.tar

$ docker load < update1.tar
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
update latest 157bcbb5fdfc 5 minutes ago 188.1 MB
ubuntu 14.04 8eaa4ff06b53 12 days ago 192.7 MB

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