牛刀小试之docker基于容器备份与恢复之export import

导出容器是指一个已经创建的容器到一个文件,不管这个容器是否在运行状态。

先查看容器:

[root@docker tmp]# docker ps -a
CONTAINER ID        IMAGE                    COMMAND                CREATED             STATUS                         PORTS               NAMES
a457769fdd92        ubuntu:14.04             "/bin/bash"            33 minutes ago      Up 33 minutes                                      backstabbing_fermi
7d3d35cb9c40        ubuntu:14.04             "/bin/bash"            49 minutes ago      Up 49 minutes                                      elegant_brattain
6aa9905ab9bc        ubuntu:14.04             "/bin/bash -c 'while   59 minutes ago      Exited (-1) 49 minutes ago                         jovial_elion
10f115a0aa25        ubuntu:14.04             "/bin/bash"            About an hour ago   Exited (0) About an hour ago                       compassionate_elion
e192cf610bda        ubuntu:14.04             "/bin/echo test"       About an hour ago   Exited (0) About an hour ago                       goofy_pasteur
c535b42dc3f2        ubuntu:14.04             "/bin/echo 'hello wo   About an hour ago   Exited (0) About an hour ago                       compassionate_wozniak
713e34e2b463        ubuntu:14.04             "/bin/bash"            About an hour ago                                                      cocky_bell
c72ad6c5adcd        ubuntu:14.04             "/bin/bash"            3 hours ago         Exited (0) 3 hours ago                             suspicious_feynman
8703418b2dec        training/webapp:latest   "echo 'hello world'"   3 hours ago         Exited (0) 3 hours ago                             pensive_curie
7f3491707dd4        ubuntu:14.04             "/bin/bash"            3 hours ago         Exited (0) 3 hours ago                             ecstatic_poincare
[root@docker tmp]#

分别导出a457769fdd92 7d3d35cb9c40 容器到test_for_run.tar test_for_stop.tar:

可以将这些文件传输到其他机器上来实现容器的迁移。
[root@docker tmp]# docker export a457 > test_for_run.tar
[root@docker tmp]# ls test_for_run.tar
test_for_run.tar
[root@docker tmp]# docker export 7d3 > test_for_stop.tar
[root@docker tmp]# ls test_for_*
test_for_run.tar  test_for_stop.tar
[root@docker tmp]#

测试导入恢复:

[root@docker tmp]# cat test_for_run.tar | docker import - test/ubuntu:v1.0
b54a803ebb42a2325fa37c8ad04ed2a9bf0cb84015068f337e80056e919952b3
[root@docker tmp]#

查看:

[root@docker tmp]# docker images test/ubuntu
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
test/ubuntu         v1.0                b54a803ebb42        51 seconds ago      192.5 MB
[root@docker tmp]#

建议在上传环境中 因容器是轻量级的,建议可以做成HA 这样就可以防止单点故障。在容器故障的时候,可以快速的切换到其他的容器。

OpsNotes wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
坚持原创技术分享,您的支持将鼓励我继续创作!