brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: docker save | gzip moves an image to a machine without registry access

Docker
~/tips/tip-docker-save-gzip-move-image-offline

docker save myapp:1.2 | gzip > myapp.tar.gz

Exports an image to a compressed archive that you can copy elsewhere and load again.

Not every server can reach a registry, and sometimes an image only exists on my laptop. An archive file solves both.

docker save myapp:1.2 | gzip > myapp.tar.gz
# copy the file to the other machine, then:
docker load < myapp.tar.gz

docker save writes the image, with all its layers and tags, as a tar archive to standard output. Piping it through gzip keeps the file small. On the target machine, docker load reads it back and the image appears in docker images with its original tag. The documentation says load accepts compressed archives too, so the gzip file can be loaded directly.

You can also skip the intermediate file and send the image straight over SSH:

docker save myapp:1.2 | gzip | ssh user@server 'gunzip | docker load'

There is a -o option to write to a file instead of using a redirect, and you can list several images in one command to put them in one archive.

The caveat is that save is for images, not for containers. It does not include volumes or the data in a running container. For that, docker export and a volume backup are different jobs. The image architecture must also match the target, since an arm64 image will not run on an amd64 machine.

Further reading: docker image save, docker image load

More Docker tips ONBUILD RUN /usr/local/bin/python-build --dir /app/src SHELL ["/bin/bash", "-c"] docker commit <container> myname/testimage:version3 docker import /path/to/exampleimage.tgz docker compose events All Docker tips (192) All topics

Link