Docker Export and Migration
This article mainly introduces the operation methods of Docker migration and backup, as well as the difference between docker save and docker export.
1 docker save
docker save
saves all layers of a Docker image to a tar file, as shown in the following commands:
|
|
The corresponding command to read with 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) to a tar file, and saves as a flattened layer, as shown in the following commands:
|
|
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 layers, configuration, and metadata of the image, retaining all the build information and version history. The output by 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 releasing applications. If there is a continuous modification and development need on the container content, it’s better to use docker commit + docker save
, which allows rollback like git.
4 Practical Test
First, make some modifications in a container, write a text file in the root directory:
|
|
Use docker export to export the container’s image:
|
|
Import the image using docker import, you can see the imported image named me:
|
|
Create a container using the imported me image and check if the previous modification in another container is retained:
|
|
It can be seen that this is not the previous container, but the modification is retained.
For individual containers, this method can be used for quick import and export, but for container groups created by docker compose, load and save need to be used. Besides the different application scenarios, the key point is that export does not save container version history, which can be considered a snapshot of a point in time. More detailed content can be referred to this article.
Besides transferring containers via files, docker hub and docker files, etc., can also be used.