Docker镜像的迁移与备份

一   选择要备份的镜像(六步)

第一步  保存镜像

docker commit 容器名称 镜像名称

第二步  查看运行的容器

[root@192 ~]
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9ddb490f2ac0 redis "docker-entrypoint.s…" 4 hours ago Up 4 hours 0.0.0.0:6379->6379/tcp, :::6379->6379/tcp myredis
90509fb78df4 nginx "/docker-entrypoint.…" 6 hours ago Up 6 hours 0.0.0.0:80->80/tcp, :::80->80/tcp mynginx

第三步  容器 mynginx 保存为新镜像 mynginx_i

[root@192 ~]
sha256:42b5d8d237ebf2ac4dc75dce3f202c3fcf52d7db07383e0649946ad13b5aaa67

第四步  查看保存的镜像 mynginx_i;

[root@192 ~]
REPOSITORY TAG IMAGE ID CREATED SIZE
mynginx_i latest 42b5d8d237eb 5 minutes ago 141MB
nginx latest 605c77e624dd 6 months ago 141MB
redis latest 7614ae9453d1 6 months ago 113MB
mysql latest 3218b38490ce 6 months ago 516MB
centos 7 eeb6ee3f44bd 9 months ago 204MB
centos/mysql-57-centos7 latest f83a2938370c 2 years ago 452MB
tomcat 7-jre7 47c156f4d4e3 3 years ago 359MB
[root@192 ~]#

第五步  创建一个 nginx 容器

[root@192 ~]
846bac2dc9a855590442e551fffe625dc77b41e567864067111956bbfb11e0e8

 第六步  nginx 访问


1.png


二   镜像备份(两步)

第一步  镜像备份

docker save -o 导出的文件名 镜像名

第二步  将镜像 mynginx_i 镜像保存为 mynginx.tar 文件

[root@192 ~]
[root@192 ~]
anaconda-ks.cfg html mynginx.tar
[root@192 ~]#


三   镜像恢复与迁移(三步)

第一步  恢复镜像

docker load -i 文件名

第二步  查看系统系统中的镜像

[root@192 ~]
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 605c77e624dd 6 months ago 141MB
redis latest 7614ae9453d1 6 months ago 113MB
mysql latest 3218b38490ce 6 months ago 516MB
centos 7 eeb6ee3f44bd 9 months ago 204MB
centos/mysql-57-centos7 latest f83a2938370c 2 years ago 452MB
tomcat 7-jre7 47c156f4d4e3 3 years ago 359MB
[root@192 ~]#

第三步  恢复mynginx.tar后查看镜像

[root@192 ~]
b5d12f59f6a7: Loading layer 18.94kB/18.94kB
Loaded image: mynginx_i:latest
[root@192 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mynginx_i latest 42b5d8d237eb 45 minutes ago 141MB
nginx latest 605c77e624dd 6 months ago 141MB
redis latest 7614ae9453d1 6 months ago 113MB
mysql latest 3218b38490ce 6 months ago 516MB
centos 7 eeb6ee3f44bd 9 months ago 204MB
centos/mysql-57-centos7 latest f83a2938370c 2 years ago 452MB
tomcat 7-jre7 47c156f4d4e3 3 years ago 359MB
[root@192 ~]#

原创文章,作者:网友投稿,如若转载,请注明出处:https://www.cloudads.cn/archives/4135.html

发表评论

登录后才能评论