Docker save, load, import, export, commit.

When I came across with the command docker export/import I was really confused as of what is it for. I usually just save my images with docker save.

The documentation just says

docker-export - Export a container's filesystem as a tar archive

and nothing more.

So after running some tests this is what I found:

To run it;

 docker export <container ID> > image-name.tar 

this will create a tarball that you can restore to an image like this

 docker import  <image-name.tar> <new image name> 

However when you try to launch a new container based off of this image you will most likely get a:

docker: Error response from daemon: No command specified.

This is because what the export/import command does, it just saves the filesystem, this means it will remove the entrypoint command as well as its history and the layers of the built container, effectively flattening the image.

If you want to access the information within the container, or just want to create a container based on an imported image you can do it givin it an entrypoint command.

docker run -ti <image ID> bash

docker run -d --entrypoint=new-command <image ID>

This is useful when you just want to save the information and have no interest in running the image as a container anymore.
If you want to create an image to run from a modified container you can do it running

docker commit <container ID> <new image name> 

and if you want to save/export it you can do it with

docker save  > image-name.tar
docker load  < image-name.tar

This will preserve all, so you can just run the image normally.

So to summarize:


docker export:
It export a container's filesystem to a tarball and it removes the history, layers and entrypoint (flattening the image), run against a container.
docker import: Imports the tarball into a repo image.
docker save: Saves an image to a tarball, this preserves the history, layers and entrypoint, run against an image.
docker load: Loads an image from a tarball into a repo image.
docker commit: Creates an image from a modified container preserving entrypoint, layers and history
.

This entry was posted in Containers, Docker, Unix, Virtualization. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*