Home DevOps How to Copy a Docker Image

How to Copy a Docker Image

by admin

I recently had the need to copy a docker image I had created locally to another docker host.
If you need to move a Docker image to another system, or if you’d like to back up an image then you can do so by using the docker save and docker load commands.

First of all, check your image name by running docker image list:

$ docker image list
REPOSITORY                     TAG                 IMAGE ID            CREATED             SIZE
nimmis/vcsim                   latest              a99cc435e5a0        7 days ago          922MB
mcr.microsoft.com/powershell   latest              c60d38f77378        13 days ago         290MB
bs4                            latest              0143b79ec7b3        2 months ago        943MB
centos                         centos7             5e35e350aded        2 months ago        203MB

Copy a Docker Image

To export your image to a tar file, run the docker save command, specifying a name for the .tar file, and the docker image name. This will save the docker image locally.

docker save -o image.tar centos

Also, note that you could add an image name during the export, for example:

docker save -o image.tar centos:v1

Next, copy your image to your target system. You could use SCP or another file transfer tool such as rsync. Once you have the image on the target system you can import the docker image by running the docker load command. This will load the docker image from the tar

docker load -i image.tar

You should get confirmation that your image has been loaded:

$ docker load -i image.tar 
Loaded image: centos:centos7
Loaded image: centos:latest

Now you can confirm that the image is available by running docker image list on the target system.

Final Thoughts

In this short article you have learnt how to copy a docker image using the docker save and docker load commands.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More