From e695b053546e6c6f30930a7e91500a7671dcbb09 Mon Sep 17 00:00:00 2001 From: GOLinux Date: Wed, 29 Jul 2015 11:16:25 +0800 Subject: [PATCH] [Translated]20150727 Easy Backup Restore and Migrate Containers in Docker.md --- ...estore and Migrate Containers in Docker.md | 91 ------------------ ...estore and Migrate Containers in Docker.md | 92 +++++++++++++++++++ 2 files changed, 92 insertions(+), 91 deletions(-) delete mode 100644 sources/tech/20150727 Easy Backup Restore and Migrate Containers in Docker.md create mode 100644 translated/tech/20150727 Easy Backup Restore and Migrate Containers in Docker.md diff --git a/sources/tech/20150727 Easy Backup Restore and Migrate Containers in Docker.md b/sources/tech/20150727 Easy Backup Restore and Migrate Containers in Docker.md deleted file mode 100644 index 7607fe58f7..0000000000 --- a/sources/tech/20150727 Easy Backup Restore and Migrate Containers in Docker.md +++ /dev/null @@ -1,91 +0,0 @@ -Translating by GOLinux! -Easy Backup, Restore and Migrate Containers in Docker -================================================================================ -Today we'll learn how we can easily backup, restore and migrate docker containers out of the box. [Docker][1] is an open source platform that automates the deployment of applications with fast and easy way to pack, ship and run it under a lightweight layer of software called container. It makes the applications platform independent as it acts an additional layer of abstraction and automation of operating system level virtualization on Linux. It utilizes resource isolation features of Linux Kernel with its components cgroups and namespace for avoiding the overhead of virtual machines. It makes the great building blocks for deploying and scaling web apps, databases, and back-end services without depending on a particular stack or provider. Containers are those software layers which are created from a docker image that contains the respective linux filesystem and applications out of the box. If we have a docker container running in our box and need to backup those containers for future use or wanna migrate those containers, then this tutorial will help you how we can backup, restore and migrate docker containers in linux operating system. - -Here are some easy steps on how we can backup, restore and migrate the docker containers in linux. - -### 1. Backing up the Containers ### - -First of all, in order to backup the containers in docker, we'll wanna see the list of containers that we wanna backup. To do so, we'll need to run docker ps in our linux machine running docker engine with containers already created. - - # docker ps - -![Docker Containers List](http://blog.linoxide.com/wp-content/uploads/2015/07/docker-containers-list.png) - -After that, we'll choose the containers we wanna backup and then we'll go for creating the snapshot of the container. We can use docker commit command in order to create the snapshot. - - # docker commit -p 30b8f18f20b4 container-backup - -![Docker Commit](http://blog.linoxide.com/wp-content/uploads/2015/07/docker-commit.png) - -This will generated a snapshot of the container as the docker image. We can see the docker image by running the command docker images as shown below. - - # docker images - -![Docker Images](http://blog.linoxide.com/wp-content/uploads/2015/07/docker-images.png) - -As we can see the snapshot that was taken above has been preserved as docker image. Now, inorder to backup that snapshot, we have two options, one is that we can login into the docker registry hub and push the image and the next is that we can backup the docker image as tarballs for further use. - -If we wanna upload or backup the image in the [docker registry hub][2], we can simply run docker login command to login into the docker registry hub and then push the required image. - - # docker login - -![Docker Login](http://blog.linoxide.com/wp-content/uploads/2015/07/docker-login.png) - - # docker tag a25ddfec4d2a arunpyasi/container-backup:test - # docker push arunpyasi/container-backup - -![Docker Push](http://blog.linoxide.com/wp-content/uploads/2015/07/docker-push.png) - -If we don't wanna backup to the docker registry hub and wanna save the image for future use in the machine locally then we can backup the image as tarballs. To do so, we'll need to run the following docker save command. - - # docker save -o ~/container-backup.tar container-backup - -![taking tarball backup](http://blog.linoxide.com/wp-content/uploads/2015/07/taking-tarball-backup.png) - -To verify if the tarball has been generated or not, we can simply run docker ls inside the directory where we saved the tarball. - -### 2. Restoring the Containers ### - -Next, after we have successfully backed up our docker containers, we'll now go for restoring those contianers which are snapshotted as docker images. If we have pushed those docker images in the registry hub, then we can simply pull that docker image and run it out of the box. - - # docker pull arunpyasi/container-backup:test - -![Docker Pull](http://blog.linoxide.com/wp-content/uploads/2015/07/docker-pull.png) - -But if we have backed up those docker images locally as tarball file, then we can easy load that docker image using docker load command followed by the backed up tarball. - - # docker load -i ~/container-backup.tar - -Now, to ensure that those docker images have been loaded successfully, we'll run docker images command. - - # docker images - -After the images have been loaded, we'll gonna run the docker container from the loaded image. - - # docker run -d -p 80:80 container-backup - -![Restoring Docker Tarball](http://blog.linoxide.com/wp-content/uploads/2015/07/restoring-docker-tarballs.png) - -### 3. Migrating the Docker Containers ### - -Migrating the containers involve both the above process ie Backup and Restore. We can migrate any docker container from one machine to another. In the process of migration, first we take the backup of the container as snapshot docker image. Then, that docker image is either pushed to the docker registry hub or saved as tarball files in the locally. If we have pushed the image to the docker registry hub, we can easily restore and run the container using docker run command from any machine we want. But if we have saved the image as tarballs locally, we can simply copy or move the image to the machine where we want to load image and run the required container. - -### Conclusion ### - -Finally, we have learned how we can backup, restore and migrate the docker containers out of the box. This tutorial is exactly same for every platform of operating system where docker runs successfully. Really, docker is pretty simple and easy to use but very powerful tool. It has pretty easy to remember commands which are short enough with many simple but powerful flags and parameters. The above methods makes us comfortable to backup our containers so that we can restore them when needed in future. This can help us recover our containers and images even if our host system crashes or gets wiped out accidentally. If you have any questions, suggestions, feedback please write them in the comment box below so that we can improve or update our contents. Thank you ! Enjoy :-) - --------------------------------------------------------------------------------- - -via: http://linoxide.com/linux-how-to/backup-restore-migrate-containers-docker/ - -作者:[Arun Pyasi][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:http://linoxide.com/author/arunp/ -[1]:http://docker.com/ -[2]:https://registry.hub.docker.com/ diff --git a/translated/tech/20150727 Easy Backup Restore and Migrate Containers in Docker.md b/translated/tech/20150727 Easy Backup Restore and Migrate Containers in Docker.md new file mode 100644 index 0000000000..420430cca8 --- /dev/null +++ b/translated/tech/20150727 Easy Backup Restore and Migrate Containers in Docker.md @@ -0,0 +1,92 @@ +无忧之道:Docker中容器的备份、恢复和迁移 +================================================================================ +今天,我们将学习如何快速地对docker容器进行快捷备份、恢复和迁移。[Docker][1]是一个开源平台,用于自动化部署应用,以通过快捷的途径在称之为容器的轻量级软件层下打包、发布和运行这些应用。它使得应用平台独立,因为它扮演了Linux上一个额外的操作系统级虚拟化的自动化抽象层。它通过其组件cgroups和命名空间利用Linux内核的资源分离特性,达到避免虚拟机开销的目的。它使得用于部署和扩展web应用、数据库和后端服务的大规模构建块无需依赖于特定的堆栈或供应者。 + +所谓的容器,就是那些创建自Docker镜像的软件层,它包含了独立的Linux文件系统和开箱即用的应用程序。如果我们有一个在盒子中运行着的Docker容器,并且想要备份这些容器以便今后使用,或者想要迁移这些容器,那么,本教程将帮助你掌握在Linux操作系统中备份、恢复和迁移Docker容器。 + +我们怎样才能在Linux中备份、恢复和迁移Docker容器呢?这里为您提供了一些便捷的步骤。 + +### 1. 备份容器 ### + +首先,为了备份Docker中的容器,我们会想看看我们想要备份的容器列表。要达成该目的,我们需要在我们运行这Docker引擎,并已创建了容器的Linux机器中运行 docker ps 命令。 + + # docker ps + +![Docker Containers List](http://blog.linoxide.com/wp-content/uploads/2015/07/docker-containers-list.png) + +在此之后,我们要选择我们想要备份的容器,然后我们会去创建该容器的快照。我们可以使用 docker commit 命令来创建快照。 + + # docker commit -p 30b8f18f20b4 container-backup + +![Docker Commit](http://blog.linoxide.com/wp-content/uploads/2015/07/docker-commit.png) + +该命令会生成一个作为Docker镜像的容器快照,我们可以通过运行 docker images 命令来查看Docker镜像,如下。 + + # docker images + +![Docker Images](http://blog.linoxide.com/wp-content/uploads/2015/07/docker-images.png) + +正如我们所看见的,上面做的快照已经作为Docker镜像保存了。现在,为了备份该快照,我们有两个选择,一个是我们可以登陆进Docker注册中心,并推送该镜像;另一个是我们可以将Docker镜像打包成tarball备份,以供今后使用。 + +如果我们想要在[Docker注册中心][2]上传或备份镜像,我们只需要运行 docker login 命令来登录进Docker注册中心,然后推送所需的镜像即可。 + + # docker login + +![Docker Login](http://blog.linoxide.com/wp-content/uploads/2015/07/docker-login.png) + + # docker tag a25ddfec4d2a arunpyasi/container-backup:test + # docker push arunpyasi/container-backup + +![Docker Push](http://blog.linoxide.com/wp-content/uploads/2015/07/docker-push.png) + +如果我们不想备份到docker注册中心,而是想要将此镜像保存在本地机器中,以供日后使用,那么我们可以将其作为tarball备份。要完成该操作,我们需要运行以下 docker save 命令。 + + # docker save -o ~/container-backup.tar container-backup + +![taking tarball backup](http://blog.linoxide.com/wp-content/uploads/2015/07/taking-tarball-backup.png) + +要验证tarball时候已经生成,我们只需要在保存tarball的目录中运行 ls 命令。 + +### 2. 恢复容器 ### + +接下来,在我们成功备份了我们的Docker容器后,我们现在来恢复这些被快照成Docker镜像的容器。如果我们已经在注册中心推送了这些Docker镜像,那么我们仅仅需要把那个Docker镜像拖回并直接运行即可。 + + # docker pull arunpyasi/container-backup:test + +![Docker Pull](http://blog.linoxide.com/wp-content/uploads/2015/07/docker-pull.png) + +但是,如果我们将这些Docker镜像作为tarball文件备份到了本地,那么我们只要使用 docker load 命令,后面加上tarball的备份路径,就可以加载该Docker镜像了。 + + # docker load -i ~/container-backup.tar + +现在,为了确保这些Docker镜像已经加载成功,我们来运行 docker images 命令。 + + # docker images + +在镜像被加载后,我们将从加载的镜像去运行Docker容器。 + + # docker run -d -p 80:80 container-backup + +![Restoring Docker Tarball](http://blog.linoxide.com/wp-content/uploads/2015/07/restoring-docker-tarballs.png) + +### 3. 迁移Docker容器 ### + +迁移容器同时涉及到了上面两个操作,备份和恢复。我们可以将任何一个Docker容器从一台机器迁移到另一台机器。在迁移过程中,首先我们将容器的备份作为快照Docker镜像。然后,该Docker镜像或者是被推送到了Docker注册中心,或者被作为tarball文件保存到了本地。如果我们将镜像推送到了Docker注册中心,我们简单地从任何我们想要的机器上使用 docker run 命令来恢复并运行该容器。但是,如果我们将镜像打包成tarball备份到了本地,我们只需要拷贝或移动该镜像到我们想要的机器上,加载该镜像并运行需要的容器即可。 + +### 尾声 ### + +最后,我们已经学习了如何快速地备份、恢复和迁移Docker容器,本教程适用于各个成功运行Docker的操作系统平台。真的,Docker是一个相当简单易用,然而功能却十分强大的工具。它的命令相当易记,这些命令都非常短,带有许多简单而强大的标记和参数。上面的方法让我们备份容器时很是安逸,使得我们可以在日后很轻松地恢复它们。这会帮助我们恢复我们的容器和镜像,即便主机系统崩溃,甚至意外地被清除。如果你还有很多问题、建议、反馈,请在下面的评论框中写出来吧,可以帮助我们改进或更新我们的内容。谢谢大家!享受吧 :-) + +-------------------------------------------------------------------------------- + +via: http://linoxide.com/linux-how-to/backup-restore-migrate-containers-docker/ + +作者:[Arun Pyasi][a] +译者:[GOLinux](https://github.com/GOLinux) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:http://linoxide.com/author/arunp/ +[1]:http://docker.com/ +[2]:https://registry.hub.docker.com/