Docker Tip #97: Save and Load Docker Images from a Zip File
You can do this to transfer images to a server without using a Docker Registry or building images directly on your server.
Prefer video? Here’s a recorded version of this tip on YouTube which covers this topic.
docker image save myimage:v1.0.0 | gzip > myimage.tar.gz
docker image load --input myimage.tar.gz
# You'll get this type of output after loading:
da5d55102092: Loading layer [==================================================>] 9.558MB/9.558MB
95ac61d1a52e: Loading layer [==================================================>] 35.5MB/35.5MB
41aaeb647441: Loading layer [==================================================>] 5.12kB/5.12kB
Loaded image: myimage:v1.0.0
We’re using gzip
here to make the file on disk smaller but technically
that’s an optional step. Using docker image save --output myimage.tar myimage:v1.0.0
works without gzip. The load command works the same in either
case because internally it can handle compressed files.
Now if you were to run docker image ls
you’ll find myimage:v1.0.0
sitting
there ready to go. Feel free to docker image rm -f myimage:v1.0.0
between
saving and loading if you want to verify that it really works!
It’s preferable to reference your Docker image:tag when saving instead of the image id because if you use the id approach you’ll lose the tag reference when you load it.
You can also pipe a few commands together to send the image to a server:
docker image save myimage:v1.0.0 | gzip | ssh user@yourhost docker image load
This could be useful if you’re building images on a CI server and then sending them to your server. This avoids your server having to build your images directly which can be resource intensive and potentially undependable in case there’s a temporary network outage.
You can also use this to transfer images to an air-gapped system through an external drive.