在我們的工作環境中,一般鏡像通過上傳到鏡像倉庫中(本地或者公共倉庫),用到時下載到服務器上即可。如果服務器不能上網,又沒有私有倉庫,我們就需要將鏡像保存爲文件上傳到服務器上,載入鏡像即可使用。
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 <centos.tar
docker images#查看到我們剛載入的鏡像