Docker 容器化技术介绍(四) 之 Docker的安装与启动
Docker 容器化技术介绍(五) 之 Docker 镜像操作
Docker 容器化技术介绍(六) 之 Docker 容器操作
Docker 容器化技术介绍(七) 之 Docker 应用部署
Docker 容器化技术介绍(八) 之 Docker 备份与迁移
1 容器保存为镜像
通过以下命令将容器保存为镜像,查看镜像可以发现多了一个新的本地镜像
docker commit 容器名称 保存的新镜像的名称
docker commit th_centos th_centos_back2
[root@bogon home]# docker commit th_centos th_centos_back2
sha256:07198478ead6dea1a3121277b6b68b52ba47aa9f9c86e2c37264d2ecbcd823bf
[root@bogon home]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
th_centos_back2 latest 07198478ead6 16 seconds ago 200 MB
docker.io/tomcat latest 690cb3b9c7d1 2 days ago 463 MB
docker.io/mysql latest 29e0ae3b69b9 10 days ago 484 MB
2 镜像备份
当把容器保存为镜像了以后,那么接下来就需要将镜像打包成一个文件
docker save -o 打包以后的文件名称 镜像名称
docker save -o th_centos_back2_image.tar th_centos_back2
-o : 表示的意思是输出
[root@bogon home]# docker save -o th_centos_back2_image.tar th_centos_back2
[root@bogon home]# ls
th th_centos_back2_image.tar
3 镜像恢复与迁移
首先我们先删除掉 th_centos_back2 镜像
[root@bogon home]# docker rmi th_centos_back2
Untagged: th_centos_back2:latest
Deleted: sha256:07198478ead6dea1a3121277b6b68b52ba47aa9f9c86e2c37264d2ecbcd823bf
Deleted: sha256:cf149eb51274693cce9e131f3692f10616eda0e65d72b915ab8efec1d52f8066
[root@bogon home]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/tomcat latest 690cb3b9c7d1 2 days ago 463 MB
docker.io/mysql latest 29e0ae3b69b9 10 days ago 484 MB
docker.io/centos latest 5182e96772bf 2 weeks ago 200 MB
docker.io/redis latest 4e8db158f18d 3 weeks ago 83.4 MB
docker.io/nginx latest c82521676580 4 weeks ago 109 MB
然后执行此命令进行恢复,发现执行恢复命令后,通过 docker images 又可以看到上面删除的镜像了
docker load -i th_centos_back2_image.tar
-i : 表示输入
[root@bogon home]# docker load -i th_centos_back2_image.tar
d83640a246b0: Loading layer [==================================================>] 4.608 kB/4.608 kB
Loaded image: th_centos_back2:latest
[root@bogon home]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
th_centos_back2 latest 07198478ead6 5 minutes ago 200 MB
docker.io/tomcat latest 690cb3b9c7d1 2 days ago 463 MB
docker.io/mysql latest 29e0ae3b69b9 10 days ago 484 MB
docker.io/centos latest 5182e96772bf 2 weeks ago 200 MB
docker.io/redis latest 4e8db158f18d 3 weeks ago 83.4 MB
docker.io/nginx latest c82521676580 4 weeks ago 109 MB