今天发现用docker import / export 来制作镜像的时候,不能复制container, 很多再container 里面install 的东西没有备份,重新安装了一下。
还是commit 提交container 里面来生成image, 最后成功了。
[root@test3 containers]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0888d8a896a5 ubuntu "/bin/bash" 2 hours ago Up 23 minutes container3
79f94b6f8740 busybox "sh" 46 hours ago Exited (1) 46 hours ago container2
417698c45ca4 busybox "sh" 46 hours ago Exited (127) 23 hours ago container1
44bae256c6d0 httpd "/bin/bash" 46 hours ago Exited (0) 43 hours ago cranky_goldberg
下面commit 一个新的image:
[root@test3 containers]# docker commit 0888d8a896a5 ubuntu-ansible
sha256:3c0c9557af3632abf8217027cbd859fd833ce403616237dc49c5cba1e7561305
[root@test3 containers]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu-ansible latest 3c0c9557af36 10 seconds ago 242MB
ubuntu-ssh-20190622 latest af84d755fccd 3 hours ago 240MB
ubuntu-ssh-20190622 ansible e91bf9461302 23 hours ago 240MB
ubuntu latest 4c108a37151f 4 days ago 64.2MB
busybox latest e4db68de4ff2 8 days ago 1.22MB
httpd latest e77c77f17b46 11 days ago 140MB
下面检查一下image 的属性,发现cmd 里面有/usr/bash, 应该是成功的image:
[root@test3 containers]# docker inspect ubuntu-ansible
。。。
"Cmd": [
"/bin/bash"
。。。
下面开始创建新的container:
[root@test3 containers]# docker run -itd --name=container4 ubuntu-ansible
2db66945bb194a30e6e822619a09597f6f42d226c50055381047b4546fd52363
[root@test3 containers]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2db66945bb19 ubuntu-ansible "/bin/bash" 5 seconds ago Up 5 seconds container4
0888d8a896a5 ubuntu "/bin/bash" 2 hours ago Up 30 minutes container3
79f94b6f8740 busybox "sh" 46 hours ago Exited (1) 46 hours ago container2
417698c45ca4 busybox "sh" 46 hours ago Exited (127) 23 hours ago container1
44bae256c6d0 httpd "/bin/bash" 46 hours ago Exited (0) 43 hours ago cranky_goldberg
发现container4 里面是有想要的东西,很棒哦。
本文介绍了使用docker制作镜像和创建容器的过程。起初使用docker import / export制作镜像时无法复制container,很多安装内容未备份。后采用commit提交container生成image成功,还展示了查看容器和镜像信息、检查镜像属性,最后创建新容器并确认其中包含所需内容。

519

被折叠的 条评论
为什么被折叠?



