Docker镜像制作方式:
- 容器转为镜像
- dockerfile
容器转为镜像(不常用)
# 将容器转为镜像
docker commit 容器id 镜像名称:版本号
# 将镜像转为压缩文件进行传输
docker save -o 压缩文件名称 镜像名称:版本号
# 将压缩文件还原为镜像
docker load -i 压缩文件名称
控制台执行:
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1f3e008ee9a3 centos "/bin/bash" 59 minutes ago Exited (0) 12 minutes ago c2
41b97000dde8 centos "/bin/bash" About an hour ago Exited (0) 54 minutes ago c1
7048bbaeb3b5 centos "/bin/bash" About an hour ago Exited (127) 12 minutes ago c3
[root@localhost ~]# docker commit 41b97000dde8 test_centos:1.0
sha256:3702cc1d86027b48e4d8aca97ac9a623d745f414a3d93ee4f020737691b0babc
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
test_centos 1.0 3702cc1d8602 13 seconds ago 231 MB
hello-world latest feb5d9fea6a5 2 months ago 13.3 kB
centos latest 5d0da3dc9764 3 months ago 231 MB
[root@localhost ~]# docker save -o test_centos.tar test_centos:1.0
[root@localhost ~]# ls
anaconda-ks.cfg data initial-setup-ks.cfg test_centos.tar 公共 模板 视频 图片 文档 下载 音乐 桌面
[root@localhost ~]# docker rmi 3702cc1d8602
Untagged: test_centos:1.0
Deleted: sha256:3702cc1d86027b48e4d8aca97ac9a623d745f414a3d93ee4f020737691b0babc
Deleted: sha256:962a2b659fadddb7fd18b7df587ae44cc3584cbc9ed0ddf6710e3496035af5ac
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/tomcat latest 24207ccc9cce 12 days ago 680 MB
mysql 5.7 738e7101490b 2 weeks ago 448 MB
hello-world latest feb5d9fea6a5 2 months ago 13.3 kB
centos latest 5d0da3dc9764 3 months ago 231 MB
192.168.126.143:5000/google_containers/pause-amd64.3.0 latest f9d5de079539 7 years ago 240 kB
192.168.156.130:5000/google_containers/pause-amd64.3.0 latest f9d5de079539 7 years ago 240 kB
192.168.156.13:5000/google_containers/pause-amd64.3.0 latest f9d5de079539 7 years ago 240 kB
docker.io/kubernetes/pause latest f9d5de079539 7 years ago 240 kB
[root@localhost ~]# docker load -i test_centos.tar
b7f31d0d1b04: Loading layer [==================================================>] 5.12 kB/5.12 kB
Loaded image: test_centos:1.0
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
test_centos 1.0 3702cc1d8602 2 minutes ago 231 MB
hello-world latest feb5d9fea6a5 2 months ago 13.3 kB
centos latest 5d0da3dc9764 3 months ago 231 MB
[root@localhost ~]#