Backup, recovery, and migration of containers in Docker

Source: Internet
Author: User
Tags docker ps docker registry

Days, we'll learn how to quickly backup, recover, and migrate Docker containers. Docker is an open-source platform for automating deployment of applications to package, publish, and run them in a fast-moving way under the lightweight software layer called containers. It makes the application platform stand-alone because it acts as an automated abstraction layer for Linux on an additional OS-level virtualization. It uses the resource separation characteristics of the Linux kernel through its component cgroups and namespaces to avoid virtual machine overhead. It enables large-scale building components for deploying and extending Web applications, databases, and back-end services without having to rely on a particular stack or provider.

The so-called container, which is the software layer created from the Docker image, contains a standalone Linux file system and an out-of-the-box application. If we have a Docker container running in the machine and want to back up these containers for future use, or want to migrate these containers, this tutorial will help you master the methods of backing up, recovering, and migrating Docker containers in the Linux operating system.

How can we back up, restore, and migrate Docker containers in Linux? Here are some handy steps for you.

650) this.width=650; "src=" http://www.linuxidc.com/upload/2015_08/150806153161271.jpg "width=" 581 "vspace=" 5 "style = "border:0px;"/>

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.

    1. # docker ps

650) this.width=650; "src=" Http://www.linuxidc.com/upload/2015_08/150806153161279.png "alt=" Docker Containers List " Width= "581" vspace= "5" style= "border:0px;"/>

Docker Containers List

After that, 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.

    1. # docker commit -p 30b8f18f20b4 container-backup

650) this.width=650; "src=" Http://www.linuxidc.com/upload/2015_08/150806153161273.png "alt=" Docker Commit "width=" 581 "vspace=" 5 "style=" border:0px; "/>

Docker Commit

This command generates a container snapshot as a Docker image, and we can view the docker images Docker image by running a command, as follows.

    1. # docker images

650) this.width=650; "src=" Http://www.linuxidc.com/upload/2015_08/150806153161272.png "alt=" Docker Images "width=" 581 "vspace=" 5 "style=" border:0px; "/>

Docker Images

As we can see, the snapshot above has been saved as a Docker image. Now, in order to back up the snapshot, we have two options, one that we can log into the Docker registry and push the image, and the other is we can package the Docker image into a tar package for future use.

If we want to upload or back up the image in the Docker registry, we only need to run the Docker login command to log into the Docker registry and then push the desired image.

    1. # docker login

650) this.width=650; "src=" Http://www.linuxidc.com/upload/2015_08/150806153161274.png "alt=" Docker Login "width=" 581 "vspace=" 5 "style=" border:0px; "/>

Docker Login

    1. # docker tag a25ddfec4d2a arunpyasi/container-backup:test

    2. # docker push arunpyasi/container-backup

650) this.width=650; "src=" Http://www.linuxidc.com/upload/2015_08/150806153161276.png "alt=" Docker Push width= "581 "Vspace=" 5 "style=" border:0px; "/>

Docker Push

If we do not want to back up to the Docker registry, but want to store 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.

    1. # docker save -o ~/container-backup.tar container-backup

650) this.width=650; "src=" Http://www.linuxidc.com/upload/2015_08/150806153161275.png "alt=" Taking Tarball backup " Width= "581" vspace= "5" style= "border:0px;"/>

Taking Tarball Backup

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

Next, after we have successfully backed up our Docker container, we now restore the containers that made the Docker image snapshot. If we have already pushed these Docker images in the registry, we just need to drag the Docker image back and run it directly.

    1. # docker pull arunpyasi/container-backup:test

650) this.width=650; "src=" Http://www.linuxidc.com/upload/2015_08/150806153161277.png "alt=" Docker Pull "width=" 581 "Vspace=" 5 "style=" border:0px; "/>

Docker Pull

However, if we back up these Docker images as tar package files locally, we can load the Docker image by using the Docker Load command, followed by the backup path of the TAR package.

    1. # docker load -i ~/container-backup.tar

Now, to make sure that these Docker images have been loaded successfully, let's run the Docker images command.

    1. # docker images

After the image is loaded, we will run the Docker container with the loaded image.

    1. # docker run -d -p 80:80 container-backup

650) this.width=650; "src=" Http://www.linuxidc.com/upload/2015_08/150806153161278.png "alt=" Restoring Docker Tarball "width=" 581 "vspace=" 5 "style=" border:0px; "/>

Restoring Docker Tarball

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. The Docker image is then either pushed to the Docker registry or saved locally as a tar package file. If we push the image to the Docker registry, we simply use the Docker Run command from any machine we want to recover and run the container. However, 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.


This article is from the "Dream to Reality" blog, please be sure to keep this source http://lookingdream.blog.51cto.com/5177800/1790966

Backup, recovery, and migration of containers in Docker

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.