docker镜像制作方法

如题所述

产品型号:Thinkpad E15
系统版本:centos8
docker镜像制作方法
Docker Image 有两种制作方法
方法1:docker commit #将容器实例的当前状态保存成image镜像
方法2:docker build #使用 Dockerfile 文件制作 image
主介绍docker commit 用法。
实战:使用docker commit生成一个apache docker镜像
1、创建一个安装好apache web服务器的容器镜像
[root@xuegod63 ~]# docker run -it centos:latest /bin/bash
[root@1d3563200047 /]# yum -y install httpd #在 container 中安装 apache 软件包
[root@1d3563200047 /]# exit
2、查看现有的images 镜像列表
[root@xuegod63 ~]# docker images #查看刚看退出的docker实例。
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 196e0ce0c9fb 13 days ago 196.6 MB注:当前只有一个centos镜像。
3、根据容器当前状态做一个image镜像,创建一个安装了apache工具的centos镜像
语法: docker commit
例:
查看刚才安装了apache软件包的的docker容器ID:
[root@xuegod63 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES1d3563200047 centos /bin/bash 10 minutes ago Exited (0) 6 minutes ago tender_joliot
以这个安装了apache软件包的docker容器实例,创建一个镜像。
[root@xuegod63 ~]# docker commit 1d3563200047 centos:apache
sha256:e5917c01599c70d0680beeb35f6df98889dd22106399efd6907d956d8a943242
[root@xuegod63 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos apache 4fd446f1034a 16 seconds ago 269MB
centos latest 0f3e07c0138f 5 weeks ago 220MB
总结:
1、创建一个安装好apache web服务器的容器镜像
2、查看现有的images 镜像列表
3、根据容器当前状态做一个image镜像,创建一个安装了apache工具的centos镜像
温馨提示:答案为网友推荐,仅供参考
相似回答