准备工作
[root@localhost ~]
.
├── anaconda-ks.cfg
└── httpd_dockerfile
├── dockerfile
└── files
├── apr-1.7.0.tar.gz
├── apr-util-1.6.1.tar.gz
├── httpd-2.4.54.tar.gz
└── install.sh
写dockerfile文件
[root@localhost httpd_dockerfile]
FROM centos
LABEL MAINTAINER "qzl 1@2.com"
EXPOSE 80 443
ENV httpd_edition 2.4.54
ENV PATH /usr/local/apache/bin:$PATH
ADD files/apr-1.7.0.tar.gz /usr/src/
ADD files/apr-util-1.6.1.tar.gz /usr/src/
ADD https:
ADD files/install.sh /tmp/
RUN /bin/bash /tmp/install.sh
WORKDIR /usr/local/apache
CMD ["-D","FOREGROUND"]
ENTRYPOINT ["/usr/local/apache/bin/httpd"]
[root@localhost httpd_dockerfile]# cat files/install.sh
#!/bin/bash
useradd -r -M -s /sbin/nologin apache && \
#
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo && \
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* && \
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-* && \
yum update -y && \
yum clean all && \
dnf -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make && \
cd /usr/src/ && \
tar xf httpd-${httpd_edition}.tar.gz && \
cd /usr/src/apr-1.7.0/ && \
sed -i '/$RM "$cfgfile"/d' configure && \
./configure --prefix=/usr/local/apr && \
make && make install && \
cd ../apr-util-1.6.1/ && \
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && \
make && make install && \
cd ../httpd-${httpd_edition}/ && \
./configure --prefix=/usr/local/apache \
--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 && \
dnf -y remove gcc gcc-c++ make && \
sed -i "/#ServerName www.example.com:80/c ServerName www.example.com:80" /usr/local/apache/conf/httpd.conf && \
rm -rf /var/log
构建镜像
[root@localhost httpd_dockerfile]
[root@localhost httpd_dockerfile]
[root@localhost httpd_dockerfile]
[root@localhost httpd_dockerfile]
[root@localhost httpd_dockerfile]
Authenticating with existing credentials...
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https:
Login Succeeded
[root@localhost httpd_dockerfile]
创建容器测试
[root@localhost files]
[root@localhost files]
e3151ac78b2dc75180cac9c184d72b5e3fa0acaad5798de5a4faa89b6071fa36
[root@localhost httpd_dockerfile]
[root@localhost files]
hello world
访问服务器IP