Dockerfile构建apache镜像(源码)
1、建立工作目录
[root@docker ~]# mkdir apache
[root@docker ~]# cd apache/
2、编写Dockerfile文件
[root@docker apache]# vim Dockerfile
#基于的基础镜像
FROM centos:7#镜像作者信息
MAINTAINER Huyang <13363571949@163.com>#安装相关依赖包
RUN yum install -y wget net-tools gcc zlib zlib-devel make openssl-devel apr apr-util apr-util-devel pere-devel#下载并解压apache源码包
RUN wget https://downloads.apache.org/httpd/httpd-2.4.57.tar.gz && tar zxf httpd-2.4.57.tar.gz
#编译安装apache
RUN cd httpd-2.4.57 && ./configure --prefix=/usr/local/apache && make && make install#开启 80端口
EXPOSE 80#定义时区
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime#启动容器时执行脚本
CMD ["-D","FOREGROUND"]
ENTRYPOINT ["/usr/local/apache/bin/apachectl"]
3、构建镜像
[root@docker apache]# docker build -t apache:new .
[root@docker apache]# docker images apache:new
4、测试容器
[root@docker apache]# docker run -d -p 8020:80 --name apche-test --restart=always apache:new
5、浏览器访问:http://192.168.100.131:8020