Docker Save, Load and Deploy

Need to deploy private Docker containers without a private registry? Try docker save and docker load.

Working set:

1
2
3
4
5
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
realguess/jq latest 1f3f837970bf 3 months ago 6.107 MB
realguess/jq 1.4 6071e18eae76 3 months ago 6.107 MB
busybox ubuntu-14.04 f6169d24347d 6 weeks ago 5.609 MB

Actions to perform:

  1. Save an image with a single tag
  2. Save an image with multiple tags
  3. Save multiple images

Save a single tagged image:

1
$ docker save realguess/jq:latest > realguess-jq-latest.tar

Save a single image with all tags:

1
$ docker save realguess/jq > realguess-jq.tar

The tagged one is slightly less in size:

1
2
3
$ ls -lh realguess*.tar
-rw-rw-r-- 1 chao chao 6.0M Feb 1 12:00 realguess-jq-latest.tar
-rw-rw-r-- 1 chao chao 6.5M Feb 1 12:00 realguess-jq.tar

Save multiple images:

1
$ docker save busybox realguess/jq > busy-realguess-jq-box.tar

The size is almost twice as much comparing to a single image tar:

1
2
$ ls -lh busy*
-rw-rw-r-- 1 chao chao 12M Feb 1 12:00 busy-realguess-jq-box.tar

Compress it:

1
$ out=busy-realguess-jq-box.tar && docker save busybox realguess/jq > $out && gzip $out

Much better in size:

1
2
$ ls -lh busy*
-rw-rw-r-- 1 chao chao 5.7M Feb 1 12:00 busy-realguess-jq-box.tar.gz

Do the reverse, load the tarred Docker images with docker load.