Skip to content

Docker image vs container persistence

In the context of Docker, persistence refers to the mechanisms used to save the state of either an Image or a Container to a file (typically a .tar archive). These two operations serve different purposes and utilize distinct commands: save for images and export for containers^[600-developer__docker__docker-tomcat.md]。

Image Persistence (docker save)

The docker save command is used to persist an image.^[600-developer__docker__docker-tomcat.md] This is useful for backing up an image or creating a portable snapshot of a specific application environment.

To use this command, you typically list the available images first^[600-developer__docker__docker-tomcat.md]:

docker images

Then, you can redirect the output of the save command to a tar file^[600-developer__docker__docker-tomcat.md]:

docker save <IMAGE_NAME_OR_ID> > /path/to/save.tar

The resulting file can be moved to another system and loaded back using docker load^[600-developer__docker__docker-tomcat.md].

Container Persistence (docker export)

The docker export command is used to persist a container.^[600-developer__docker__docker-tomcat.md] This captures the current state of the filesystem of a specific container instance, rather than the image template it was created from.

To perform this operation, you first identify the specific container you wish to export^[600-developer__docker__docker-tomcat.md]:

docker ps -a

Then, you specify the container ID to export its state to a tar file^[600-developer__docker__docker-tomcat.md]:

docker export <CONTAINER_ID> > /path/to/export.tar

Comparison

  • Target: docker save targets images, whereas docker export targets containers^[600-developer__docker__docker-tomcat.md]。
  • Scope: Image persistence preserves the layered filesystem and image metadata (enabling full restoration with layers), while container persistence flattens the filesystem into a single tarball of the container's current state.

Sources

  • 600-developer__docker__docker-tomcat.md