镜像导入导出
在缺乏网络的环境中,可以将Docker
镜像导出,进行离线部署。
一、save && load
docker save
命令可以将多个镜像导出到文件中,用法如下:
>docker save --help
Usage: docker save [OPTIONS] IMAGE [IMAGE...]
Save one or more images to a tar archive (streamed to STDOUT by default)
Options:
--help Print usage
-o, --output string Write to a file, instead of STDOUT
例如:
docker save -o wq_ci.tar postgres:10 jenkins/jenkins:lts sonarqube:lts
在导出完成后,可以使用docker load -i <saved_image.tar>
来加载导出的image
。
二、export && import
docker export
可以将container
导出,用法如下:
>docker export --help
Usage: docker export [OPTIONS] CONTAINER
Export a container's filesystem as a tar archive
Options:
--help Print usage
-o, --output string Write to a file, instead of STDOUT
例如:
docker export -o postgres-export.tar postgres
使用docker import
可以从导出文件生成image
,例如:
docker import postgres-export.tar postgres:latest
三、save和export区别
docker save
保存的是image
,docker export
保存的是container
;docker load
用来载入image
,docker import
用来载入container
包,但两者都会恢复为image
;docker load
不能对载入的image
重命名,而docker import可以为image
指定新名称。
Last updated
Was this helpful?