Skip to content

Docker container persistence

Docker container persistence refers to the process of saving the state of a specific container instance to a file. This allows the container's filesystem or configuration to be moved, archived, or reloaded later^[600-developer-docker-docker-tomcat.md, 600-developer__docker__docker-tomcat.md].

The standard command used to achieve this is docker export.^[600-developer-docker-docker-tomcat.md, 600-developer__docker__docker-tomcat.md]

Command usage

To persist a running or stopped container, you must first identify its unique Container ID using the listing command:^[600-developer-docker-docker-tomcat.md, 600-developer__docker__docker-tomcat.md]

docker ps -a

Once the ID is obtained, the export command is used to write the container's state to a tar file^[600-developer-docker-docker-tomcat.md, 600-developer__docker__docker-tomcat.md]:

docker export <CONTAINER ID> > /home/export.tar

Comparison with Image Persistence

While the export command is used to persist containers, the save command is used to persist images^[600-developer-docker-docker-tomcat.md, 600-developer__docker__docker-tomcat.md]. The workflow for saving an image involves listing the images and then outputting the specific image to a tar file^[600-developer-docker-docker-tomcat.md, 600-developer__docker__docker-tomcat.md]:

docker images
docker save busybox-1 > /home/save.tar
  • [[Docker Image]]
  • [[Docker Container]]
  • [[Docker Volume]]

Sources

  • 600-developer-docker-docker-tomcat.md
  • 600-developer__docker__docker-tomcat.md