首先:第二台机器上也要装有docker,版本能够不一致。html
参考:blog.csdn.net/sunbocong/a… 实验环境 操做系统:CentOS Linux release 7.3.1611 (Core) docker版本: 17.11.0-ce 镜像备份nginx
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
eg_postgresql latest 431a93e7033e weeks ago 318MB
centos latest 3fa822599e10 weeks ago 204MB
hello-world latest f2a91732366c weeks ago 1.85kB
复制代码
并压缩生成压缩包hello-world-lastest.tar.gzweb
[root@localhost ~]# docker save hello-world |gzip >hello-world-lastest.tar.gz
[root@localhost ~]# ls
anaconda-ks.cfg Documents hello-world-lastest.tar.gz Music Pictures Templates
Desktop Downloads initial-setup-ks.cfg original-ks.cfg Public Videos
复制代码
这里我使用的是一台机器,因此先删除hello-world镜像,再使用加载命令恢复: 删除镜像:sql
[root@localhost ~]# docker rmi f2a91732366c --force
Untagged: hello-world:latest
Untagged: hello-world@sha256:be0cd392e45be79ffeffa6b05338b98ebb16c87b255f48e297ec7f98e123905c
Deleted: sha256:f2a91732366c0332ccd7afd2a5c4ff2b9af81f549370f7a19acd460f87686bc7
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
eg_postgresql latest 431a93e7033e weeks ago 318MB
centos latest 3fa822599e10 weeks ago 204MB
复制代码
[root@localhost ~]# docker load -i hello-world-lastest.tar.gz
Loaded image: hello-world:latest
复制代码
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
eg_postgresql latest 431a93e7033e weeks ago 318MB
centos latest 3fa822599e10 weeks ago 204MB
hello-world latest f2a91732366c weeks ago 1.85kB
复制代码
发现hello-world镜像已经成功恢复.docker
参考:blog.csdn.net/u011142756/…centos
docker commit nginx mynginx
复制代码
nginx是容器名称 mynginx是新的镜像名称 此镜像的内容就是你当前容器的内容,接下来你能够用此镜像再次运行新的容器bash
- docker save -o mynginx.tar mynginx
复制代码
o 输出到的文件 执行后,运行ls命令便可看到打成的tar包ide
首先咱们先删除掉mynginx镜像 而后执行此命令进行恢复post
docker load -i mynginx.tar
复制代码
-i 输入的文件 执行后再次查看镜像,能够看到镜像已经恢复ui
首先,建立目录 nginx, 用于存放后面的相关东西
[root@localhost ~]# mkdir -p ~/dockerdata/nginx/html ~/dockerdata/nginx/logs ~/dockerdata/nginx/conf
复制代码
[root@localhost ~]# run -d -p 8081:80 --name container-nginx-web -v ~/dockerdata/nginx/html:/usr/share/nginx/html -v ~/dockerdata/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v ~/dockerdata/nginx/logs:/var/log/nginx mynginx
复制代码