Docker教程小白实操入门(9)--基于export导出容器与基于import导入一个镜像

一、需求

从容器导出一份镜像

二、将“容器的文件系统”保存到tar包

docker export [OPTIONS] CONTAINER
  • OPTIIONS: 命令选项,-o指定写到一个文件中,而不是标准输出流中;
  • Container: 需要导出到tar包的容器。

例如:

# 将busyboxContainer导出为容器快照:busybox.tar
docker export busyboxContainer > busybox.tar

三、从tar包导入一个镜像

docker import [OPTIONS] 文件|URL|- [镜像名]
  • OPTIIONS: 命令选项;
  • 文件|URL|: 指定docker import的对象,可以是文件或者某个URL
  • [镜像名]: 以<仓库名>:<标签>的方式来指定。
# 从busybox.tar中加载镜像,镜像名为busybox:v1.0
cat busybox.tar | docker import - busybox:v1.0

四、完整例子

#拉取busybox 最新镜像
docker run --name busyboxContainer busybox echo "hello"


# 将busyboxContainer导出为容器快照:busybox.tar
docker export busyboxContainer > busybox.tar


# 查看是否打包完整
ls


# 查看是否存在该镜像
docker images busybox 


# 从busybox.tar中加载镜像,镜像命名为busybox:v1.0 
cat busybox.tar | docker import - busybox:v1.0


# 查看是否存在该镜像
docker images busybox

五、docker export和docker save的区别

两者的操作对象不同。

docker save是将一个镜像保存为一个tar包;

docker export是将一个容器快照保存为一个tar包。

参考:https://www.educoder.net/shixuns/4uyn5ebp/challenges

猜你喜欢

转载自blog.csdn.net/u013288190/article/details/108910071