Backup, recovery, and migration of containers in Docker
1. Backup container
First, to back up the containers in Docker, we would like to look at the list of containers we want to back up. To achieve this, we need to run the Docker PS command in the Linux machine where we run the Docker engine and have created the container
# docker PS
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/7D/83/wKioL1bqGFugGixBAAATp4Gvne0509.png "title=" 1.png " alt= "Wkiol1bqgfuggixbaaatp4gvne0509.png"/> after this, we want to select the container that we want to back up, and then go to create a snapshot of the container. We can use the Docker commit command to create a snapshot.
# docker Commit-p 30b8f18f20b4 Container-backup
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/7D/85/wKiom1bqGAjiw3rKAAAad3_LGqo001.png "title=" 2.png " alt= "Wkiom1bqgajiw3rkaaaad3_lgqo001.png"/>
This command generates a container snapshot as a Docker image, and we can view the Docker image by running the Docker Images command, as follows.
# Docker Images
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/7D/85/wKiom1bqGDCBB94hAAAWz-WisTs713.png "title=" 3.png " alt= "Wkiom1bqgdcbb94haaawz-wists713.png"/> as we can see, the snapshot above has been saved as a Docker image.
If you want to save this image on a local machine for later use, we can back it up as a tar package. To complete this operation, we need to run the following Docker Save command.
# docker Save-o ~/container-backup.tar Container-backup
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7D/83/wKioL1bqGQ2zPb8qAAAb6GjtjiM582.png "title=" 4.png " alt= "Wkiol1bqgq2zpb8qaaab6gjtjim582.png"/>
To verify that the TAR package has been generated, we only need to run the LS command in the directory where the tar package is saved.
2. Recovering containers
If we back up the Docker image as a tar package file locally, we can load the Docker image by using the Docker Load command, followed by a backup path to the TAR package.
# docker Load-i ~/container-backup.tar
Now, to make sure that these Docker images are loaded successfully, let's run the Docker images command
< Span style= "Font-family:tahoma, Arial, ' song Body '; Font-size:14px;line-height:25.2px;background-color:rgb (255,255,255);" > # Docker images
< Span style= "Font-family:tahoma, Arial, ' song Body '; Font-size:14px;line-height:25.2px;background-color:rgb (255,255,255);" > in the mirror is loaded , we will use the loaded image to run the Docker container.
< Span style= "Font-family:tahoma, Arial, ' song Body '; Font-size:14px;line-height:25.2px;background-color:rgb (255,255,255);" > # Docker run-d-P 80:80 container-backup
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/7D/86/wKiom1bqGyDho5M_AAAYPYtNibA295.png "title=" 4.png " alt= "Wkiom1bqgydho5m_aaaypytniba295.png"/>3. Migrating Docker containers
The migration container also involves the above two operations, backup and recovery. We can migrate any Docker container from one machine to another machine. During the migration process, we will first back up the container as a Docker image snapshot. If we pack the image into a tar package and back it up locally, we just need to copy or move the image onto the machine we want, load the image and run the required container.
Docker Migration Container