How to package and transfer Docker images from one server to another – CloudSavvy IT





If you’ve created a Docker image on your development machine and want to deploy it to a server, you can use a Docker registry, but Docker also has tools to save images to files and upload them to a different server. .

You don’t need a container registry

Typically, to transfer a version of a container (called an image) to a remote server, you use a Docker container registry. This is by far the best method: it is a single point of authority, making it easy to distribute updates across multiple servers. It also doesn’t require you to make the container public; there are many great private container registries out there, such as Google’s GCR and AWS’s ECS. The Docker Hub even supports private repositories. If you’re just concerned about privacy, switch to a private registry and keep using docker push and docker pull.

However, for those looking to do it the old fashioned way, the Docker CLI contains tools for saving images to files and uploading them to a remote server.

To save an image, you can use docker save, specifying an output file, then specifying an image name and tag:

docker save -o ./savedimage imagename:tag

If you don’t specify a tag, Docker will package all the tags.

This will serialize and save a copy of the image as the output file. The image is stored in a tar file. If you want to save it as tar.gz, you can omit the -o flag and redirect the output to gzip:

docker save imagename:tag | gzip > savedimage.tar.gz

You can then take this file and scp or an FTP copy on the target server. Once it’s there you can use docker load to import it again:

docker load -i savedimage

This will make the image available on the target system as if you had run docker build . -t imagename. You can use it as a locally built image with docker container run:

docker container run imagename




Leave a Comment

x