docker container migration across servers

  • 2020-06-03 08:56:44
  • OfStack

There are two backup modes of docker: export and save.

export is the current state for the container and docker save for the mirror images.

export

Find the ID to back up the container


[root@wls12c ~]$ docker ps -a
CONTAINER ID    IMAGE        COMMAND       CREATED       STATUS          NAMES
037b847bf093    centos       "/bin/bash"     3 minutes ago    Exited (0) 2 minute   naughty_davinci  

The backup


[root@wls12c ~]$ docker export 037b847bf093 >centos_demo.tar
[root@wls12c ~]$ du -sh centos_demo.tar 
195M  centos_demo.tar

export is a container packed into one tar package.

restore

Package the backup centos_demo.tar to the target server


[root@11g ~]$ cat centos_demo.tar |docker import - centos:demo
8962416d1362f289ceb9848e21a95f03dc34eb6f234c8f98f1a6e1ec7fe34a67

View the newly generated image


[root@11g ~]$ docker images
REPOSITORY     TAG         IMAGE ID      CREATED       VIRTUAL SIZE
centos       demo        8962416d1362    24 seconds ago   196.7 MB

save

Get the mirror name


[root@wls12c ~]$ docker images
REPOSITORY     TAG         IMAGE ID      CREATED       VIRTUAL SIZE
centos       latest       d83a55af4e75    3 weeks ago     196.7 MB

The backup image


[root@wls12c ~]$ docker save centos >centos_save.tar

To restore the mirror


[root@11g ~]$ docker load <centos_save.tar 

View the restored mirror


[root@wls12c ~]$ docker images
REPOSITORY     TAG         IMAGE ID      CREATED       
centos       latest       d83a55af4e75    3 weeks ago     196.7 MB

Differences between the two:

Images exported and imported (ES55en-ES56en) lose all history, while images saved and loaded (ES57en-ES58en) do not lose history and layers (layer). This means that you cannot rollback to the previous layer (layer) by exporting and then importing, and you can rollback to the previous layer (docker tag) by persisting the entire image with a save and then load method < LAYER ID > < IMAGE NAME > Roll back and forth before the layer).


Related articles: