How to share Docker objects through export

If you want to share a Docker image, you can do so:

  • through a Docker Registry,
  • by a Docker CLI command.

Docker provides several commands to share a Docker image:

  • export: creates a .tar file from the container's file system,
  • import: creates a Docker image with the filesystem from a .tar file,
  • save: creates a .tar file from a Docker image with its history,
  • load: creates a Docker image with its history from a .tar file.

The docker load command keeps the history of the image, unlike the docker import command.

To create a container from an existing one, use docker import and docker export.

Let’s get the devopstestlab/nginx-helloworld image locally:

docker pull devopstestlab/nginx-helloworld

The image is pulled:

Using default tag: latest
latest: Pulling from devopstestlab/nginx-helloworld
d3e14976: Pulling fs layer
2c78f105: Pulling fs layer
a6b9e4bd: Pulling fs layer
Digest: sha256:3385ecc3c20a714d257c59c8cbffc7d6e681a6b38c34db6dd43beb48197f3f80
Status: Downloaded newer image for devopstestlab/nginx-helloworld:latest

Let’s check that it has been downloaded:

docker images

The list of local images is displayed:

REPOSITORY                       TAG                 IMAGE ID            CREATED             SIZE
devopstestlab/nginx-helloworld latest 9468dea24c09 7 months ago 19.7MB

Let’s create a .tar file containing this Docker image and its history:

docker save devopstestlab/nginx-helloworld > nginx-helloworld.tar

A file nginx-helloworld.tar has been created:

ls -l nginx-helloworld.tar

We can see the file:

-rw-r--r--  1 cq  staff  20990464 13 nov 15:19 nginx-helloworld.tar

Lets delete the image that was downloaded:

docker rmi devopstestlab/nginx-helloworld

The image is locally deleted:

Untagged: devopstestlab/nginx-helloworld:latest
Untagged: devopstestlab/nginx-helloworld@sha256:3385ecc3c20a714d257c59c8cbffc7d6e681a6b38c34db6dd43beb48197f3f80
Deleted: sha256:9468dea24c09bae2058918f1585a4d64116ada7a76a65aeac72349ec633813b5
Deleted: sha256:78e313105a7ff240099cabc0bf65d93be4c06b4684b17d4190449eb7c0555478
Deleted: sha256:d19e30a5a02f87c9d49a16e811318e114a7423bf3f87115daba61ec5865de498
Deleted: sha256:06072639d98612614b2266f6252368a0ad0d54e5c70731f5b63c9d70a1dc3e0c
Deleted: sha256:531743b7098cb2aaf615641007a129173f63ed86ca32fe7b5a246a1c47286028

Let’s check that it has been deleted:

docker images

There is no image locally:

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

Let’s recreate the Docker image from the backup:

docker load --input nginx-helloworld.tar

The image is recreated:

43b7098c: Loading layer  5.819MB/5.819MB
cf4d16de: Loading layer 15.14MB/15.14MB
e5cf1923: Loading layer 3.584kB/3.584kB
Loaded image: devopstestlab/nginx-helloworld:latest

Let’s check that the image has been recreated:

docker images

We can see again the image:

REPOSITORY                       TAG                 IMAGE ID            CREATED             SIZE
devopstestlab/nginx-helloworld latest 9468dea24c09 7 months ago 19.7MB

You now know how to create an image share by going through an export in .tar format.

More articles on my blog

My DevOpsTestLab Youtube channel.

My LinkedIn profile:

Interests in the full lifecycle: design, Agile Coaching, development, testing, DevOps, Cloud, Management 3.0, ITIL. It defines me.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store