In this guide, we will look at how you can export and import Docker images and containers. Before you can export a Docker container, you need to commit the changes into an image and tag it appropriately. Docker has an export command which enables you to migrate Docker images / containers from one Docker host system to a different node.
In my Local Docker system, I have the following Docker images.
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
goharbor/harbor-exporter v2.11.0 b31607386be1 6 weeks ago 108MB
goharbor/redis-photon v2.11.0 184984d263c2 6 weeks ago 165MB
goharbor/trivy-adapter-photon v2.11.0 10ef7b73394b 6 weeks ago 518MB
goharbor/harbor-registryctl v2.11.0 f1220f69df90 6 weeks ago 162MB
goharbor/registry-photon v2.11.0 95046ed33f52 6 weeks ago 84.5MB
goharbor/nginx-photon v2.11.0 681ba9915791 6 weeks ago 153MB
goharbor/harbor-log v2.11.0 a0a812a07568 6 weeks ago 163MB
goharbor/harbor-jobservice v2.11.0 bba862a3784a 6 weeks ago 159MB
goharbor/harbor-core v2.11.0 2cf11c05e0e2 6 weeks ago 185MB
goharbor/harbor-portal v2.11.0 ea8fda08df5b 6 weeks ago 162MB
goharbor/harbor-db v2.11.0 9bd788ea0df6 6 weeks ago 271MB
goharbor/prepare v2.11.0 2baf15fbf5e2 6 weeks ago 207MB
Export Docker images
In the first exercise, we will export the Docker images as they are and move them to the second Node running Docker engine.
docker save goharbor/prepare:v2.11.0 > goharbor-prepare.tar
The docker save flag is used to save one or more images to a tar archive.
For running Docker containers, first create a new image from a container’s changes.
docker commit --change "Added something" webapp webapp:v2
docker save webapp:v2 > webapp_v2.tar
Where webapp is the name of container running.
Import Saved Docker images
Copy exported docker images archive to destination server, then import them using the docker import command.
$ docker load < <file>.tar
Getting image source signatures
Copying blob 5f91d4a491de: 829.12 MiB / 834.23 MiB [===========================]
Copying blob 5f91d4a491de: 834.23 MiB / 834.23 MiB [=======================] 11s
Copying config dd85e44a0f8b: 419 B / 419 B [================================] 0s
Writing manifest to image destination
Storing signatures
dd85e44a0f8bcf876749eabaeae5924ab6778b5ce191b37e08d4874982d8a601
Copy image ID and tag it properly.
docker tag 4e1a2b349b09 rook/ceph:master
More Learning materials:
There you have it. You have learned how to export and import Docker images and containers. until next time, stay connected for updated and check other Docker related content on our website.
The exact command to import a Docker image is “docker load”, not “docker import” (cf. https://docs.docker.com/engine/reference/commandline/load/).
Correct. Thanks for commenting on this. We’ve updated the article.