參考教程:
https://docs.docker.com/engine/reference/commandline/save/
https://docs.docker.com/engine/reference/commandline/load/
環境
- virtual box 6.1
- centos 7.8
- docker 19.03
命令格式
docker save [OPTIONS] IMAGE [IMAGE...]
docker load [OPTIONS]
使用 save 可以保存鏡像到文件,而 load 可以將導出的文件再次導入生成一個鏡像。
命令選項
save 命令選項
| 名稱 | 默認值 | 描述 |
| --output , -o
| | 寫到指定的文件中,而不是標准輸出流上 |
load 命令選項
名稱 | 默認值 | 描述 |
---|---|---|
--input , -i |
從文件加載而不是從標准輸入流 | |
--quiet , -q |
不顯示輸出信息 |
示例
保存鏡像
[root@master docker]# docker save busybox > busybox.tar
[root@master docker]# ls -sh busybox.tar
1.4M busybox.tar
[root@master docker]# docker save --output obusybox.tar busybox
[root@master docker]# ls -sh
total 2.7M
1.4M busybox.tar 1.4M obusybox.tar
[root@master docker]#
使用另外的 tag 保存鏡像
[root@master docker]# docker save -o mytag_busybox.tar busybox busybox:mytag
[root@master docker]# ls -sh
total 4.0M
1.4M busybox.tar 1.4M mytag_busybox.tar 1.4M obusybox.tar
保存壓縮鏡像
[root@master docker]# docker save busybox | gzip > busybox.tar.gz
[root@master docker]# ls -sh
total 4.7M
1.4M busybox.tar 688K busybox.tar.gz 1.4M mytag_busybox.tar 1.4M obusybox.tar
[root@master docker]#
輸入流加載鏡像
[root@master docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
[root@master docker]# docker load < obusybox.tar
Getting image source signatures
Copying blob 988c34d733d9 done
Copying config a34cc20fa7 done
Writing manifest to image destination
Storing signatures
Loaded image(s): docker.io/library/busybox:latest
[root@master docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/library/busybox latest a34cc20fa773 6 weeks ago 1.37 MB
[root@master docker]#
加載鏡像
[root@master docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
[root@master docker]# docker load -i obusybox.tar
Getting image source signatures
Copying blob 988c34d733d9 done
Copying config a34cc20fa7 done
Writing manifest to image destination
Storing signatures
Loaded image(s): docker.io/library/busybox:latest
[root@master docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/library/busybox latest a34cc20fa773 6 weeks ago 1.37 MB
[root@master docker]#
加載壓縮鏡像
[root@master docker]# docker load -i busybox.tar.gz
Getting image source signatures
Copying blob 988c34d733d9 done
Copying config a34cc20fa7 done
Writing manifest to image destination
Storing signatures
Loaded image(s): docker.io/library/busybox:latest
[root@master docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/library/busybox latest a34cc20fa773 6 weeks ago 1.37 MB
[root@master docker]#
加載另外 Tag
[root@master docker]# ls
busybox.tar busybox.tar.gz mytag_busybox.tar obusybox.tar
[root@master docker]# docker load < mytag_busybox.tar
Getting image source signatures
Copying config a34cc20fa7 done
Writing manifest to image destination
Storing signatures
Getting image source signatures
Copying config a34cc20fa7 done
Writing manifest to image destination
Storing signatures
Loaded image(s): docker.io/library/busybox:latest, docker.io/library/busybox:mytag
[root@master docker]#
總結
介紹了 save/load 命令的使用,可以將鏡像導出成文件,並根據文件再次還原為鏡像。