docker 镜像的导出与导入 save 与 load

一、镜像导出

docker save 导出

将系统中的镜像保存为压缩包,进行文件传输。使用 docker save --help 查看命令各参数,或者去docker官网查看.以 hello-world镜像为例。

A:将镜像保存为tar包

docker save image > package.tar

bash 复制代码
docker save 9c7a54a9a43c > hello-world.tar
[root@localhost ~]# ll | grep hello-world.tar 
-rw-r--r--. 1 root root      23040 8月  13 00:40 hello-world.tar

docker save -o/--output package.tar image

bash 复制代码
[root@localhost ~]# docker save -o hello-world-o.tar 9c7a54a9a43c
[root@localhost ~]# ll | grep hello-world-o.tar 
-rw-------. 1 root root      23040 8月  13 00:47 hello-world-o.tar

B:将镜像保存为tar.gz包 (可以使压缩包更小)

docker save image | gzip > hello-world.tar.gz

bash 复制代码
[root@localhost ~]# docker save 9c7a54a9a43c | gzip > hello-world.tar.gz
[root@localhost ~]# ll hello-world.tar.gz 
-rw-r--r--. 1 root root 3439 8月  13 00:52 hello-world.tar.gz

总结:可以看出tar.gz 明显比tar 占用的内存更少

二、镜像导入

docker load 导入

A: 使用 < 将压缩包加载为镜像

docker load < package.tar.gz

bash 复制代码
[root@localhost ~]# docker load < hello-world.tar.gz 
Loaded image ID: sha256:9c7a54a9a43cca047013b82af109fe963fde787f63f9e016fdc3384500c2823d

B: 使用 -i / --input 参数将压缩包加载成镜像

docker load -i package.tar

bash 复制代码
[root@localhost ~]# docker load -i hello-world.tar
Loaded image ID: sha256:9c7a54a9a43cca047013b82af109fe963fde787f63f9e016fdc3384500c2823d
相关推荐
虎头金猫1 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
分布式存储与RustFS1 天前
MinIO 官方 Docker 镜像被移除:依赖它的项目该怎么办
docker·云原生·devops·对象存储·minio·分布式存储
AI职业加油站1 天前
AI智能体应用工程师证书:政策红利下的职业新风口
大数据·运维·人工智能·学习·职场发展
此冬歌咏1 天前
K8s 节点故障实战:优雅驱逐 31 秒,硬故障 331 秒,以及那个永远 Pending 的 Pod
运维·k8s
玉&心1 天前
通过Arthas在线诊断K8S中的内存及JVM等使用情况
docker·k8s·arthas
xing-xing1 天前
Docker容器中Nginx站点根目录网页配置访问
nginx·docker
-梅2 天前
linux(8) 软硬链接
linux·运维·服务器
赵文宇(温玉)2 天前
CoreDNS的hosts插件的缺行配置导致k8s集群异常
容器·kubernetes·rancher
guo_wen_qiang2 天前
上传本地镜像到harbor中
docker·容器·持续部署
张洛闻Eren2 天前
k8s云原生【第十课】:水平 Pod 自动扩缩容
运维·数据库·云原生·kubernetes·github