Docker備份和遷移

docker備份和遷移目錄.png

首先:第二臺機器上也要裝有docker,版本能夠不一致。html

1、Docker鏡像遷移

參考:blog.csdn.net/sunbocong/a… 實驗環境 操做系統:CentOS Linux release 7.3.1611 (Core) docker版本: 17.11.0-ce 鏡像備份nginx

1.查看現有docker鏡像:

[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

複製代碼

2.將鏡像hello-world保存爲歸檔文件:

並壓縮生成壓縮包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

複製代碼

3.加載鏡像

這裏我使用的是一臺機器,因此先刪除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

複製代碼

4.加載鏡像的歸檔文件包:

[root@localhost ~]# docker load -i hello-world-lastest.tar.gz 
Loaded image: hello-world:latest

複製代碼

5.檢查機器中的鏡像:

[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

2、容器保存爲鏡像

參考:blog.csdn.net/u011142756/…centos

1.經過如下命令將容器保存爲鏡像

docker commit nginx mynginx

複製代碼

nginx是容器名稱 mynginx是新的鏡像名稱 此鏡像的內容就是你當前容器的內容,接下來你能夠用此鏡像再次運行新的容器bash

2.鏡像備份

- docker  save -o mynginx.tar mynginx
複製代碼

o 輸出到的文件 執行後,運行ls命令便可看到打成的tar包ide

3.鏡像恢復與遷移

首先咱們先刪除掉mynginx鏡像 而後執行此命令進行恢復post

docker load -i mynginx.tar

複製代碼

-i 輸入的文件 執行後再次查看鏡像,能夠看到鏡像已經恢復ui

4.運行容器

首先,建立目錄 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
複製代碼
相關文章
相關標籤/搜索