案例要求:需要centos镜像下的httpd环境直接打包成新的镜像,直接使用
准备:一台装有docker环境的虚拟机,拉取centos:7的镜像(最新的也可以)
1.使用docker commit构建镜像
- 拉取镜像
创建环境
[root@xiongan /]# yum clean all [root@xiongan /]# yum install -y httpd [root@xiongan /]# vi /var/www/html/index.html [root@xiongan /]# httpd -k start #使httpd服务立即生效
【扩展】:
此为httpd的配置文件中servername没有修改 95行 ServerName loaclhost:80
[root@xiongan /]# curl http://172.17.0.2 hello,docker-xiongan
以上环境就搭建完成
#使用docker commit 构建新的镜像 [root@docker-tz ~]# docker commit xiongan centos-httpd:v1
2.使用docker build构建镜像-Dockerfile
- 创建dockerfile目录
在本机内创建dockerfile目录→创建Dockerfile文件 run-httpd.sh文件 index.html文件 编辑脚本内容
Dockerfile: FROM centos:7 MAINTAINER "tz taozi@taozi.com" RUN yum clean all RUN yum -y install httpd ADD run-httpd.sh /run-httpd.sh RUN chmod 755 /run-httpd.sh ADD index.html /var/www/html EXPOSE 80 WORKDIR / CMD ["/bin/bash","/run-httpd.sh"] run-httpd.sh: #! /bin/bash rm -rf /run/httpd* exec /sbin/httpd -D FOREGROUND
- 测试执行
[root@docker-tz dockerbuild]# docker build -t centos-test:v1 .
#末尾有个. 不要丢掉 代表当前运行目录下的脚本文件
1 条评论
2025年10月新盘 做第一批吃螃蟹的人coinsrore.com
新车新盘 嘎嘎稳 嘎嘎靠谱coinsrore.com
新车首发,新的一年,只带想赚米的人coinsrore.com
新盘 上车集合 留下 我要发发 立马进裙coinsrore.com
做了几十年的项目 我总结了最好的一个盘(纯干货)coinsrore.com
新车上路,只带前10个人coinsrore.com
新盘首开 新盘首开 征召客户!!!coinsrore.com
新项目准备上线,寻找志同道合 的合作伙伴coinsrore.com
新车即将上线 真正的项目,期待你的参与coinsrore.com
新盘新项目,不再等待,现在就是最佳上车机会!coinsrore.com
新盘新盘 这个月刚上新盘 新车第一个吃螃蟹!coinsrore.com