How to copy Docker images from one host to another without using a repository – Dev

The best answers to the question “How to copy Docker images from one host to another without using a repository” in the category Dev.

QUESTION:

How do I transfer a Docker image from one machine to another one without using a repository, no matter private or public?

I create my own image in VirtualBox, and when it is finished I try to deploy to other machines to have real usage.

Since it is based on my own based image (like Red Hat Linux), it cannot be recreated from a Dockerfile. My dockerfile isn’t easily portable.

Are there simple commands I can use? Or another solution?

ANSWER:

Transferring a Docker image via SSH, bzipping the content on the fly:

docker save <image> | bzip2 | ssh [email protected] docker load

Note that docker load automatically decompresses images for you. It supports gzip, bzip2 and xz.

It’s also a good idea to put pv in the middle of the pipe to see how the transfer is going:

docker save <image> | bzip2 | pv | ssh [email protected] docker load

(More info about pv: home page, man page).

Important note from @Thomas Steinbach: on high bandwidth, bzip won’t be able to compress fast enough. In case you can upload at 10 MB/s and more, gzip/gunzip will be much faster than bzip2.

If you’re on 3G and your Internet is slow, @jgmjgm suggests that you can use xz: it offers a higher compression ratio.

ANSWER:

You will need to save the Docker image as a tar file:

docker save -o <path for generated tar file> <image name>

Then copy your image to a new system with regular file transfer tools such as cp, scp or rsync(preferred for big files). After that you will have to load the image into Docker:

docker load -i <path to image tar file>

PS: You may need to sudo all commands.

EDIT:
You should add filename (not just directory) with -o, for example:

docker save -o c:/myfile.tar centos:16

ANSWER:

You can use a one-liner with DOCKER_HOST variable:

docker save app:1.0 | gzip | DOCKER_HOST=ssh://[email protected] docker load

ANSWER:

To save an image to any file path or shared NFS place see the following example.

Get the image id by doing:

docker images

Say you have an image with id “matrix-data”.

Save the image with id:

docker save -o /home/matrix/matrix-data.tar matrix-data

Copy the image from the path to any host. Now import to your local Docker installation using:

docker load -i <path to copied image file>