I am assuming you already have a docker image that you now want to move to another host. In this example I have two web server containers I want to move called web1 and web2.
Now we can to export image web1 to a file. This is simple using docker
save -o web1.image
However, if we pipe the output to bzip2 we can reduce the size of this image significantly.
In the image below you can see I have gone from 125mb to 42mb in size.
docker save web1 | bzip2 > web1.image.bz2
not a bad reduction especially if you are moving larger images over smaller pipes.
Now you can scp the file to the remote host and then load the image into your remote docker instance. Docker supports compressed files so you don’t have to extract the bz image file.
docker load < web1.image.bz2
Next simply run your image. In this example I giving the container a name “web1”, running it in daemon mode on port 8081 which connects to port 80 on the actual container. The last web1 argument is the name of the image file.
docker run --name web1 -d -p 8081:80 web1
Now that you see the steps we can condense these into one command which hopefully looks less like magic now and more like a neat shortcut.
docker save web2 | bzip2 | ssh user@remotehost 'bunzip2 | docker load; docker run -d -p 8082:80 web2‘