(Last Updated On: August 29, 2019)

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.

$ sudo 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.

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

sudo docker commit --change "Added something" webapp webapp:v2
sudo 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.

$ sudo docker import 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
dd85e44a0f8bcf876749eabaeae5924ab6778b5ce191b37e08d4874982d8a601

Copy image ID and tag it properly.

 sudo docker tag 4e1a2b349b09 rook/ceph:master

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.

Best Books To learn Docker and Ansible Automation

How To Install Harbor Docker Image Registry on CentOS / Debian / Ubuntu

How To Install Latest Docker Compose on Linux

How To run Local Kubernetes clusters in Docker

How To run Docker Containers using Podman and Libpod