利用docker 中的container 来创建新的image

本文介绍了使用docker制作镜像和创建容器的过程。起初使用docker import / export制作镜像时无法复制container,很多安装内容未备份。后采用commit提交container生成image成功,还展示了查看容器和镜像信息、检查镜像属性,最后创建新容器并确认其中包含所需内容。

今天发现用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 里面是有想要的东西,很棒哦。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

shenghuiping2001

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值