Dockerfile构建apache镜像

创建工作目录

[root@localhost ~]# mkdir tomcat
[root@localhost ~]# cd tomcat/

编写配置文件

[root@localhost tomcat]# cat Dockerfile
#基于的基础镜像
FROM centos:7
 
#镜像作者信息
MAINTAINER liu
 
#安装相关依赖包
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"]

构建镜像

[root@localhost tomcat]# docker build -t apache:new .

[root@localhost tomcat]#  docker images apache:new
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
apache              new                 79d3192369be        25 seconds ago      1.19 GB

测试容器

[root@localhost tomcat]# docker run -d -p 8010:80 --name apache-test apache:new
5885a3ab583774690ac551c7a5cb6d7d956d0451b89447314b56b5616280d373
[root@localhost tomcat]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
5885a3ab5837        apache:new          "/usr/local/apache..."   11 seconds ago      Up 10 seconds       0.0.0.0:8010->80/tcp   apache-test

网页访问

Dockerfile构建apache镜像_第1张图片

 

你可能感兴趣的:(apache,docker)