一、export命令
server1:
[root@localhost ~]# docker run --name web01 -d -p 8080:80 nginx
069c6fc112fcf50faa53eafc52059e49dffec91039ca2f48fdf901ae5fe8ab34
[root@localhost ~]# docker exec -it web01 /bin/bash
root@069c6fc112fc:/# cd /usr/share/nginx/html/
root@069c6fc112fc:/usr/share/nginx/html# echo "Hello Docker" > index.html
root@069c6fc112fc:/usr/share/nginx/html# exit
exit
[root@localhost ~]# docker stop web01
web01
[root@localhost ~]# docker export -o web01.tar web01
[root@localhost ~]# scp web01.tar 10.207.237.127:/root/
The authenticity of host '10.207.237.127 (10.207.237.127)' can't be established.
ECDSA key fingerprint is SHA256:4YPih/C/0Z9jnvrazhUnpoZOm8x3EeWXLERqk1b7xtg.
ECDSA key fingerprint is MD5:f7:97:fb:71:a4:2a:b1:01:a9:2a:cc:4e:27:e9:c4:30.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.207.237.127' (ECDSA) to the list of known hosts.
root@10.207.237.127's password:
web01.tar 100% 129MB 2.2MB/s 00:58
server2:
[root@localhost ~]# docker import web01.tar web01
sha256:b15eab35aaf85f720511fafa04741af525939c9bd3f57c0cd0b2e9570e474e3b
[root@localhost ~]# docker image ls -a
REPOSITORY TAG IMAGE ID CREATED SIZE
web01 latest b15eab35aaf8 20 seconds ago 131MB
[root@localhost ~]# docker run -it -p 8080:80 web01 /bin/bash
root@f619706f8b2c:/# cat /usr/share/nginx/html/index.html
Hello Docker
二、save命令
server1:
[root@localhost ~]# docker run --name web02 -d -p 8080:80 nginx
f43ea8e8fe92131d087d49070a8297c0c79396053d20ee502f039fe4937441f6
[root@localhost ~]# docker exec -it web02 /bin/bash
root@f43ea8e8fe92:/# echo "Hello Docker" > /usr/share/nginx/html/index.html
root@f43ea8e8fe92:/# cat /usr/share/nginx/html/index.html
Hello Docker
root@f43ea8e8fe92:/# exit
exit
[root@localhost ~]# docker stop web02
web02
[root@localhost ~]# docker commit web02 web02
sha256:5b2cd8129a6fd6e03a7c7ff2518a0912783ad046b4b57f2b205a3d64f4ee4b31
[root@localhost ~]# docker save -o web02.tar web02
[root@localhost ~]# scp web02.tar 10.207.237.127:/root/
root@10.207.237.127's password:
web02.tar 100% 131MB 2.2MB/s 01:00
[root@localhost ~]#
server2:
[root@localhost ~]# docker load -i web02.tar
dbf0533c2a76: Loading layer [==================================================>] 16.38kB/16.38kB
Loaded image: web02:latest
[root@localhost ~]# docker run --name web02 -d -p 80:80 web02
485f09ca306e139cdb2d790fdc044573d080fb70ae950ca077441692a86c690d
[root@localhost ~]# docker exec -it web02 /bin/bash
root@485f09ca306e:/# cat /usr/share/nginx/html/index.html
Hello Docker