Docker容器技术 配置、部署与应用电子活页-02.02.在离线环境中导入镜像.docx
在离线环境中导入镜像
离线环境无法联网,不能直接执行dockerpull命令从公网下载Docker镜像,但可以利用Docker镜像的导入导出功能从其他计算机上导入镜像。下面进行示范。
(1)先从一个联网的Docker主机上拉取Docker镜像。
[root@host1~]#dockerpullhello-world
Usingdefaulttag:latest
latest:Pullingfromlibrary/hello-world
Digest:sha256:92695bc579f31df7a63da6922075d0666e565ceccad16b59c3374d2cf4e8e50e
Status:Imageisuptodateforhello-world:latest
(2)使用dockersave命令将镜像导出到归档文件中,也就是将镜像保存到本地文件中。
[root@host1~]#dockersave--outputhello-world.tarhello-world
[root@host1~]#ls-shhello-world.tar
16Khello-world.tar
(3)准备一台离线的Docker主机(前提是已经安装有DockerEngine)。
(4)将归档文件复制到离线的Docker主机上。
(5)使用dockerload命令从归档文件加载该镜像。
[root@host3~]#dockerload--inputhello-world.tar
af0b15c8625b:Loadinglayer[==================================================]3.584kB/3.584kB
Loadedimage:hello-world:latest
(6)使用dockerimages命令查看刚加载的镜像。
[root@host3~]#dockerimages
REPOSITORY TAG IMAGEID CREATED SIZE
hello-world latest fce289e99eb9 3minutesago 1.84kB
(7)基于该镜像启动一个容器。
[root@host3~]#dockerrunhello-world
HellofromDocker!
Thismessageshowsthatyourinstallationappearstobeworkingcorrectly.
……
这表明可以成功运行镜像了。
当然,还可以离线制作特定功能的Docker镜像,这需要编写Dockerfile文件。