How To Export and Import Docker Images / Containers

Posted on 93 views

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
rook/ceph           master              d55319cc22f8        12 hours ago        852MB
ceph/ceph           v14.2.2-20190826    9bd6baa6e20a        7 days ago          774MB

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 rook/ceph:master > rook-ceph.tar
docker save ceph/ceph:v14.2.2-20190826 > ceph.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 < rook-ceph.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

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.


Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.