美文网首页【收集】Docker实战集锦
容器(9)--docker镜像--docker commit镜像

容器(9)--docker镜像--docker commit镜像

作者: Explorer_z | 来源:发表于2020-03-17 22:44 被阅读0次

方法 :docker commit

创建一个安装好 apache 工具的容器镜像

[root@xuegod63 ~]# docker run -it docker.io/centos:latest /bin/bash
[root@1d3563200047 /]# yum -y install httpd      #在 container 中安装 apache 软件包
[root@1d3563200047 /]# exit
查看 images 列表
[root@xuegod63 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/centos   latest   196e0ce0c9fb 13 days ago 196.6 MB     注:当前只有一个 image centos

根据容器当前状态做一个 image 镜像:创建一个安装了 apache 工具的 centos 镜像
语法: docker commit <container 的 ID> <image_name>
例:
查看容器 ID:

[root@xuegod63 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED  STATUS PORTS NAMES
1d3563200047 centos "/bin/bash" 10 minutes ago  Exited (0) 6 minutes ago

[root@xuegod63 ~]# docker  commit   1d3563200047   docker.io/centos:apache
sha256:e5917c01599c70d0680beeb35f6df98889dd22106399efd6907d956d8a943242
[root@xuegod63 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED  SIZE
docker.io/centos apache 38fa5452c20d 5 seconds ago  304.3 MB
docker.io/centos latest 196e0ce0c9fb 13 days ago   196.6 MB

使用新创建的 docker.io/centos:apache 镜像,生成一台容器实例:
镜像,生成一台容器实例:

[root@xuegod63 ~]# docker run -it centos:apache /bin/bash
[root@8b1afc920454 /]# rpm -qa httpd #查看,已经安装好 apache 命令
httpd-2.4.6-67.el7.centos.2.x86_64

注:说明基于 apache 镜像的容器创建成功。

相关文章

网友评论

    本文标题:容器(9)--docker镜像--docker commit镜像

    本文链接:https://www.haomeiwen.com/subject/pjzjqhtx.html