千家信息网

通过把docker镜像保存为文件载入到别的服务器

发表于:2025-02-07 作者:千家信息网编辑
千家信息网最后更新 2025年02月07日,在我们的工作环境中,一般镜像通过上传到镜像仓库中(本地或者公共仓库),用到时下载到服务器上即可。如果服务器不能上网,又没有私有仓库,我们就需要将镜像保存为文件上传到服务器上,载入镜像即可使用。1、保存
千家信息网最后更新 2025年02月07日通过把docker镜像保存为文件载入到别的服务器

在我们的工作环境中,一般镜像通过上传到镜像仓库中(本地或者公共仓库),用到时下载到服务器上即可。如果服务器不能上网,又没有私有仓库,我们就需要将镜像保存为文件上传到服务器上,载入镜像即可使用。

1、保存镜像为文件

命令:

#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

例:

docker images|grep centos#查看需要保存的镜像

centos latest 0f3e07c0138f 2 months ago 220MB

docker save -o centos.tar centos#把镜像保存为centos.tar文件,ls可以查看到该文件。

2、文件载入镜像

命令:

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 centos.tar

或者:

docker load

docker images#查看到我们刚载入的镜像


0