Docker镜像保存加载
保存镜像
docker save [OPTIONS] IMAGE [IMAGE...]
docker save [-o 保存路径/包名.tar] [镜像名:tag]
加载镜像
docker load [OPTIONS]
docker load -i 包名
保存镜像后压缩
docker save [repository]:[tag] | gzip > 包名
加载镜像文件
gunzip -c 包名 | docker load
练习命令
01 命令: 显示当前目录下 文件大小而不显示其他详细信息: ls -lh
02 使用重定向操作符(>)将输出重定向到文件, 不会根据文件名后缀自动执行相应压缩操作,
所以 redirect.tgz、redirect.tar两者文件内容及占用大小相同(即 真的只是个文件名而已), 需要进一步压缩需要使用管道操作符借助gzip命令实现
[root@rancher4 ~]# pwd # 定位当前目录
/root
[root@rancher4 ~]# cd /data
[root@rancher4 ~]# mkdir tmp2024.02.20
[root@rancher4 ~]# cd tmp2024.02.20
[root@rancher4 tmp2024.02.20]# # 查看镜像列表, 选一个来测试docker命令
[root@rancher4 tmp2024.02.20]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.177.177:77777/fake-mosaic/fake-api 20240127-163757 3ec0cfa3b111 3 weeks ago 414MB
[root@rancher4 tmp2024.02.20]#
[root@rancher4 tmp2024.02.20]# # 打包保存镜像
[root@rancher4 tmp2024.02.20]# docker save -o output 192.168.177.177:77777/fake-mosaic/fake-api:20240127-163757
[root@rancher4 tmp2024.02.20]# docker save -o output-name.tar 192.168.177.177:77777/fake-mosaic/fake-api:20240127-163757
[root@rancher4 tmp2024.02.20]# # 通过重定向打包保存镜像
[root@rancher4 tmp2024.02.20]# docker save 192.168.177.177:77777/fake-mosaic/fake-api:20240127-163757 > redirect.tgz
[root@rancher4 tmp2024.02.20]# docker save 192.168.177.177:77777/fake-mosaic/fake-api:20240127-163757 > redirect.tar
[root@rancher4 tmp2024.02.20]# # 通过管道进一步压缩
[root@rancher4 tmp2024.02.20]# docker save 192.168.177.177:77777/fake-mosaic/fake-api:20240127-163757 | gzip > redirect.tar.gz
[root@rancher4 tmp2024.02.20]# docker save 192.168.177.177:77777/fake-mosaic/fake-api:20240127-163757 | gzip > redirect.tgz.gz
[root@rancher4 tmp2024.02.20]#
[root@rancher4 tmp2024.02.20]# ls -lh
总用量 2.2G
-rw------- 1 root root 402M 2月 20 19:55 output
-rw-r--r-- 1 root root 214M 2月 20 20:02 output-commpression.tar.gz
-rw------- 1 root root 402M 2月 20 19:55 output-name.tar
-rw-r--r-- 1 root root 402M 2月 20 19:55 redirect.tar
-rw-r--r-- 1 root root 214M 2月 20 19:56 redirect.tar.gz
-rw-r--r-- 1 root root 402M 2月 20 19:55 redirect.tgz
-rw-r--r-- 1 root root 214M 2月 20 19:56 redirect.tgz.gz
[root@rancher4 tmp2024.02.20]#
[root@rancher4 tmp2024.02.20]# #进一步压缩打包文件
[root@rancher4 tmp2024.02.20]# tar -zcvf output-commpression.tar.gz output
output
[root@rancher4 tmp2024.02.20]#
[root@rancher4 tmp2024.02.20]# # 解压
[root@rancher4 tmp2024.02.20]# gunzip -c redirect.tgz.gz > /data/tmp2024.02.20/comp/redirect.tgz.gz-77 | docker load
-bash: /data/tmp2024.02.20/comp/redirect.tgz.gz-77: 没有那个文件或目录
open /data/docker-data/tmp/docker-import-575586361/repositories: no such file or directory
[root@rancher4 tmp2024.02.20]# mkdir comp
[root@rancher4 tmp2024.02.20]# gunzip -c output-commpression.tar.gz > /data/tmp2024.02.20/comp/output-compression-77 | docker load
open /data/docker-data/tmp/docker-import-546729028/repositories: no such file or directory
[root@rancher4 tmp2024.02.20]# gunzip -c redirect.tgz.gz > /data/tmp2024.02.20/comp/redirect.tgz.gz-77 | docker load
open /data/docker-data/tmp/docker-import-708755667/repositories: no such file or directory
[root@rancher4 tmp2024.02.20]# ls -lh /data/tmp2024.02.20/comp
总用量 803M
-rw-r--r-- 1 root root 402M 2月 20 20:26 output-compression-77
-rw-r--r-- 1 root root 402M 2月 20 20:26 redirect.tgz.gz-77

浙公网安备 33010602011771号