容器保存为镜像
我们可以通过以下命令将容器保存为镜像文章源自堕落的鱼-https://www.duoluodeyu.com/2625.html
docker commit nginx mynginx文章源自堕落的鱼-https://www.duoluodeyu.com/2625.html
nginx是容器名称文章源自堕落的鱼-https://www.duoluodeyu.com/2625.html
mynginx是新的镜像名称文章源自堕落的鱼-https://www.duoluodeyu.com/2625.html
此镜像的内容就是你当前容器的内容,接下来你可以用此镜像再次运行新的容器文章源自堕落的鱼-https://www.duoluodeyu.com/2625.html
镜像备份
docker save -o mynginx.tar mynginx文章源自堕落的鱼-https://www.duoluodeyu.com/2625.html
-o 输出到的文件文章源自堕落的鱼-https://www.duoluodeyu.com/2625.html
执行后,运行ls命令即可看到打成的tar包文章源自堕落的鱼-https://www.duoluodeyu.com/2625.html
镜像恢复与迁移
首先我们先删除掉mynginx镜像文章源自堕落的鱼-https://www.duoluodeyu.com/2625.html
然后执行此命令进行恢复文章源自堕落的鱼-https://www.duoluodeyu.com/2625.html
docker load -i mynginx.tar文章源自堕落的鱼-https://www.duoluodeyu.com/2625.html
-i 输入的文件文章源自堕落的鱼-https://www.duoluodeyu.com/2625.html
执行后再次查看镜像,可以看到镜像已经恢复文章源自堕落的鱼-https://www.duoluodeyu.com/2625.html