Docker Export and Migration
This article mainly introduces the operation methods of Docker migration and backup, and the difference between docker save and docker export.
1 docker save
docker save saves all layers of a Docker image into a tar file, with the command as follows:
|
|
The corresponding read command for docker save
is docker load
.
2 docker export
docker export saves the current state of a Docker container (whether the container is running or stopped) into a tar file, and saves it as a flattened layer, with the command as follows:
|
|
The corresponding command for docker export
is docker import
.
3 Differences between docker save and docker export
The tar file output by docker save
contains all the layers, configurations, and metadata of the image, retaining all build information and version history of the image. The output of docker export
is a flattened file system, containing only the current state of the container, without any build or layer information. Generally, the result of export
is smaller in size, suitable for publishing applications. If there is a need for continuous modification and development of container content, it is better to use docker commit + docker save
, which allows rollback like git.
4 Actual Test
First, make some modifications in a container, write a text file in the root directory:
|
|
Export the container image using docker export:
|
|
Import the image using docker import, and you can see the image named me is imported:
|
|
Create a container using the imported me image, and check if the modifications made in another container are retained:
|
|
You can see this is not the previous container, but the modifications are retained.
For a single container, this method can be used for quick import and export, but if it is a group of containers created by docker compose, load and save need to be used. The key difference between load and import, besides the different usage scenarios, is that export does not save the container’s version history, and can be considered as a snapshot at a point in time. For more detailed content, you can refer to this article.
Besides transferring containers using files, you can also use Docker Hub and Dockerfile, etc.