docker镜像/容器的导入导出简介

说明:在实际运用中,经常会遇到服务迁移、升级或者部署等问题,想要快速的实现,可以使用docker镜像的方式,把事先准备好的docker镜像导入在目标服务器中即可。

一、save与export、load与import比较

save:导出镜像, 会将镜像完整保存,包括历史版本和元数据信息,所以文件会比export导出大,适合做服务迁移或备份;
load:导入镜像,会把版本和元数据信息一起导进去;

export:把容器导出为镜像,只把镜像当前的状态保存下来,没有历史版本等信息,所有文件比较小;
import:把容器导入为镜像;

注:导出的文件皆为 .tar 格式的

二、docker镜像的导入导出命令: save、load

1. 命令-- save

[root@mvxl8369 ~]# docker save --help
Usage:  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

解释: 将一个或多个镜像以流的方式保存在tar中
公式:

     #  docker  save  -o  xxxx.tar    <image1>:<tag1>   <image2>:<tag2>  .....
 或  #  docker  save   >  xxxx.tar    <image1>:<tag1>   <image2>:<tag2>  .....
 翻译 # docker  save  -o   目标.tar    <镜像名称>:<标签>  ....

实例:

     [root@mvxl8369 test]# docker  save  -o  organization.tar  organization:v1
     [root@mvxl8369 test]# docker  save   >  organization2.tar  organization:v1

2. 命令-- load

[root@mvxl8369 ~]# docker load --help
Usage:  docker load [OPTIONS]
Load an image from a tar archive or STDIN
Options:
  -i, --input string   Read from tar archive file, instead of STDIN
  -q, --quiet          Suppress the load output

公式:

 #  docker  load -i  xxxx.tar
 或  #  docker  load  <  xxxx.tar

三、docker容器的导入导出 import、export

1. 命令-- export

[root@mvxl8369 backup]# docker export --help
Usage:  docker export [OPTIONS] CONTAINER
Export a container's filesystem as a tar archive
Options:
  -o, --output string   Write to a file, instead of STDOUT

公式:

 #  docker  export -o  xxxx.tar  容器名/ID
 或  #  docker  export   >  xxxx.tar 容器名/ID

2. 命令-- import

[root@mvxl8369 backup]# docker import --help
Usage:  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

公式:

 #  docker  import  xxxx.tar                            导入原镜像名称和tag
 #  docker  import  xxxx.tar   <image:tag>     导入时对镜像重命名和tag
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值