三、docker--镜像的导入与导出

目录

1.save和load

        1.0在ubuntu系统上下载一个ubuntu镜像

        1.1save保存镜像

        1.2传输sc-ubuntu.tar

        1.3load导入镜像

 2.export和import

        2.0在ubuntu系统上下载一个centos镜像

       2.1使用centos镜像创建一个容器

        2.2export导出镜像

        2.3传输文件

        2.4import导入文件 

3.两组命令的区别


准备环境:

        Ubuntu 20.04

        CentOS Stream 8

        Docker 20.10.13

1.save和load

        1.0在ubuntu系统上下载一个ubuntu镜像

        #因为我下载过了,所以会显示如上

        1.1save保存镜像

        docker save [OPTIONS] IMAGE [IMAGE...]

Save one or more images to a tar archive (streamed to STDOUT by default)

Options:
  -o, --output string   Write to a file, instead of STDOUT #输出为一个文件

sc-ubuntu.tar为目标文件,ubuntu为源镜像名(image:tags)

        1.2传输sc-ubuntu.tar

scp sc-ubuntu.tar root@123.56.3.24:/root

        1.3load导入镜像


        docker load [OPTIONS]

Load an image from a tar archive or STDIN

Options:
  -i, --input string   Read from tar archive file, instead of STDIN #从一个rat文件中读入
  -q, --quiet          Suppress the load output

sc-ubuntu.tar为要读取的tar文件

 2.export和import

        2.0在ubuntu系统上下载一个centos镜像

       2.1使用centos镜像创建一个容器

        #因为export是从容器(container)中导出,所以需要创建一个容器。

        #运行或停止的容器都可以export出

        2.2export导出镜像

        docker export [OPTIONS] CONTAINER

Export a container's filesystem as a tar archive

Options:
  -o, --output string   Write to a file, instead of STDOUT  #保存到文件

        2.3传输文件

scp sc-centos.tar root@123.56.3.24:/root

        

        2.4import导入文件 

        docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]

Import the contents from a tarball to create a filesystem image

Options:
  -c, --change list       Apply Dockerfile instruction to the created image
  -m, --message string    Set commit message for imported image
      --platform string   Set platform if server is multi-platform capable

#sc-centos.tar为要读取的文件 centos:7为命名镜像名和版本号

3.两组命令的区别

        save和load是从镜像(images)中导入导出.

        export和import是从容器(container)中导入导出.

        #两组不能搭配使用!

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值