Docker image export and import

A: “为什么要导镜像,直接从网上下载不就行了?”
B: “too young too naive,你以为哪里都能上网的,谁家的机房没事都能上个youtube,google的吗”

一般的公司内网环境是无法访问Internet的,自然也无从下载基础 docker 基础镜像。但这个时候领导交给你的任务–比如用容器运行一个 Java 程序,你在本地程序都调试好了,也在docker container形式运行良好,但是怎么搬到服务器上,这个时候最原始的U盘就大有用处了(虽然现在都是云盘,但是服务器所在网络就好比你小时候玩的小霸王学习机,只能自己和自己玩儿)。

your PC –> U Disk –> Server

Steps:

1.Export image (导出镜像,在你自己的电脑上执行)

docker save Image

1
2
3
4
5
➜  docker images  | grep python
python 3-alpine c02a3409ee5b 6 weeks ago 86.7MB
➜ docker save c02a3409ee5b > my_python.tar
➜ ls -l
-rw-r--r-- 1 xxx staff 90526208 4 7 21:33 my_python.tar

更建议用镜像名称去处理,如 docker save python:3-alpine > my_python.tar ;好处是在load后镜像名称保持一致,而不是没有tag的

2.乾坤大挪移

拷贝这个tar包到U 盘,然后插到(或者是挂载)Server上

3.Import image (导入镜像)
1
2
docker load < my_python.tar
docker tag 9045 my_python:1.0 //通常还需要重新命名一下,以便可读

More Ref:

  1. https://jingsam.github.io/2017/08/26/docker-save-and-docker-export.html
  2. https://www.jianshu.com/p/8408e06b7273
Donate
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2019-2024 John Doe
  • Visitors: | Views:

请我喝杯咖啡吧~