Docker基于centos镜像编译安装httpd

Docker基于centos镜像编译安装httpd

项目目录:

[root@localhost ~]# tree
.
├── anaconda-ks.cfg
└── apache
    ├── Dockerfile
    └── packages
        ├── apr-1.7.0.tar.gz
        ├── apr-util-1.6.1.tar.gz
        └── httpd-2.4.46.tar.bz2

制作httpd镜像的Dockerfile

[root@localhost ~]# vim apache/Dockerfile 

FROM centos

LABEL MAINTAINER='leidazhuang [email protected]'

ENV apr_version=1.7.0 apr_util_version=1.6.1 httpd_version=2.4.46

ADD packages/apr-${apr_version}.tar.gz /usr/src
ADD packages/apr-util-${apr_util_version}.tar.gz /usr/src
ADD packages/httpd-${httpd_version}.tar.bz2 /usr/src

RUN yum -y install make gcc gcc-c++ openssl-devel pcre-devel expat-devel libtool libxml2-devel &&\
    useradd -r -M -s /sbin/nologin apache &&\
    cd /usr/src/apr-${apr_version} &&\
    sed -i '/$RM "$cfgfile"/d' configure &&\
    ./configure --prefix=/usr/local/apr && make && make install &&\
    cd /usr/src/apr-util-${apr_util_version} &&\
    ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr &&\
    make && make install &&\
    cd /usr/src/httpd-${httpd_version} &&\
    ./configure --prefix=/usr/local/apache \
    --sysconfdir=/etc/httpd24 \
    --enable-so \
    --enable-ssl \
    --enable-cgi \
    --enable-rewrite \
    --with-zlib \
    --with-pcre \
    --with-apr=/usr/local/apr \
    --with-apr-util=/usr/local/apr-util/ \
    --enable-modules=most \
    --enable-mpms-shared=all \
    --with-mpm=prefork && make && make install &&\
    sed -i '/#ServerName/s/#//g' /etc/httpd24/httpd.conf

WORKDIR /usr/local/apache

EXPOSE 80 443

ENTRYPOINT /usr/local/apache/bin/apachectl  -DFOREGROUND

创建镜像

[root@localhost apache]docker build -t httpd:v0.1 /root/apache/

Step 10/10 : ENTRYPOINT /usr/local/apache/bin/apachectl  -DFOREGROUND
 ---> Running in 066680bb2291
Removing intermediate container 066680bb2291
 ---> 2acab10c568a
Successfully built 2acab10c568a
Successfully tagged httpd:v0.1

启动容器,开放端口

[root@localhost apache]# docker run -it --rm --name ldz -p 80:80 httpd:v0.1
# 正常运行

查看端口信息

[root@localhost ~]# ss -antl
State       Recv-Q      Send-Q           Local Address:Port           Peer Address:Port      
LISTEN      0           128                    0.0.0.0:22                  0.0.0.0:*         
LISTEN      0           128                    0.0.0.0:80                  0.0.0.0:*         
LISTEN      0           128                       [::]:22                     [::]:* 

访问测试

[root@localhost ~]# curl 192.168.110.20
<html><body><h1>It works!</h1></body></html>

通过网页访问

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_46363008/article/details/114978495