一、需求
1. 备份某个镜像备份;
2. 将本机的某个镜像传给另外一台机器。
二、将镜像保存到tar包
docker save [OPTIONS] IMAGE [IMAGE...]
OPTIIONS
:命令选项,-o
指定写到一个文件中,而不是标准输出流中;IMAGE
: 需要保存到tar
包的镜像,可以指定多个,用空格隔开。
例如:
# 将busybox:latest镜像保存到tar包
docker save busybox:latest > busybox.tar
三、从tar包加载镜像
docker load [OPTIONS]
OPTIIONS
: 命令选项,-i
指定从一个tar
文件中读取,而不是标准输入流中。
例如:
# 从tar包加载busybox:latest镜像
docker load < busybox.tar
四、完整例子
# 首先拉取一个busybox镜像
docker pull busybox:latest
# 查看是否存在该镜像
docker images busybox
# 将busybox:latest镜像保存到tar包
docker save busybox:latest > busybox.tar
# 查看是否打包完整
ls
#删除busybox:latest镜像
docker rmi busybox:latest
# 查看是否存在该镜像
docker images busybox
# 从tar包加载busybox:latest镜像
docker load < busybox.tar
# 查看是否存在该镜像
docker images busybox
参考:https://www.educoder.net/shixuns/4uyn5ebp/challenges