Dockerfile编译安装apache案例
[root@master ~]# mkdir apache
[root@master ~]# cd apache/
[root@master apache]# touch Dockerfile
[root@master apache]# ls
Dockerfile
[root@master apache]# wget http://archive.apache.org/dist/httpd/httpd-2.4.49.tar.gz
--2021-12-07 23:20:59-- http://archive.apache.org/dist/httpd/httpd-2.4.49.tar.gz
正在解析主机 archive.apache.org (archive.apache.org)... 138.201.131.134, 2a01:4f8:172:2ec5::2
正在连接 archive.apache.org (archive.apache.org)|138.201.131.134|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:9421895 (9.0M) [application/x-gzip]
正在保存至: “httpd-2.4.49.tar.gz”
httpd-2.4.49.tar.gz 100%[===========================================================>] 8.99M 7.61KB/s 用时 17m 7s
2021-12-07 23:38:06 (8.96 KB/s) - 已保存 “httpd-2.4.49.tar.gz” [9421895/9421895])
[root@master apache]# wget https://dlcdn.apache.org//apr/apr-util-1.6.1.tar.gz
--2021-12-07 23:38:46-- https://dlcdn.apache.org//apr/apr-util-1.6.1.tar.gz
正在解析主机 dlcdn.apache.org (dlcdn.apache.org)... 151.101.2.132, 2a04:4e42::644
正在连接 dlcdn.apache.org (dlcdn.apache.org)|151.101.2.132|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:554301 (541K) [application/x-gzip]
正在保存至: “apr-util-1.6.1.tar.gz”
apr-util-1.6.1.tar.gz 100%[===========================================================>] 541.31K 478KB/s 用时 1.1s
2021-12-07 23:38:49 (478 KB/s) - 已保存 “apr-util-1.6.1.tar.gz” [554301/554301])
[root@master apache]# wget https://dlcdn.apache.org//apr/apr-1.7.0.tar.gz
--2021-12-07 23:39:30-- https://dlcdn.apache.org//apr/apr-1.7.0.tar.gz
正在解析主机 dlcdn.apache.org (dlcdn.apache.org)... 151.101.2.132, 2a04:4e42::644
正在连接 dlcdn.apache.org (dlcdn.apache.org)|151.101.2.132|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1093896 (1.0M) [application/x-gzip]
正在保存至: “apr-1.7.0.tar.gz”
apr-1.7.0.tar.gz 100%[===========================================================>] 1.04M 25.3KB/s 用时 32s
2021-12-07 23:40:03 (33.0 KB/s) - 已保存 “apr-1.7.0.tar.gz” [1093896/1093896])
[root@master apache]# ls
apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz Dockerfile httpd-2.4.49.tar.gz
[root@master apache]# vim Dockerfile
[root@master apache]# cd
[root@master ~]# tree httpd
apache
├── Dockerfile
└── files
├── apr-1.7.0.tar.gz
├── apr-util-1.6.1.tar.gz
└── httpd-2.4.49.tar.gz
1 directory, 4 files
[root@master ~]#
[root@master apache]# cat Dockerfile
FROM centos
LABEL MAINTAINER="yanghaixx 2568887571@qq.com"
ENV apache_apr 1.7.0
ENV apache_apr_util 1.6.1
ENV apache_httpd 2.4.49
ADD files/* /usr/src/
WORKDIR /usr/src/
RUN rm -rf /etc/yum.repos.d/* && \
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-$(awk -F'"' 'NR==2{print $2}' /etc/os-release).repo && \
yum -y install openssl-devel pcre-devel pcre expat-devel libtool gcc gcc-c++ make && \
cd apr-${apache_apr} && \
sed -i '/$RM "$cfgfile"/d' configure && \
./configure --prefix=/usr/local/apr && make && make install && \
cd ../apr-util-${apache_apr_util} && \
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && \
make && make install && \
cd ../httpd-${apache_httpd} && \
./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 && \
sed -i '/#ServerName/s/#//g' /usr/local/apache/conf/httpd.conf
EXPOSE 80
ENV PATH /usr/local/apache/bin:$PATH
CMD ["-D","FOREGROUND"]
ENTRYPOINT ["/usr/local/apache/bin/httpd"]
[root@master apache]# cd
[root@master ~]# docker build -t yanghaixx/apache apache
Sending build context to Docker daemon 11.08MB
Step 1/6 : FROM centos
---> 5d0da3dc9764
Step 2/6 : LABEL MAINTAINER="yanghaixx 2568887571@qq.com"
---> Using cache
---> 57ee107cc395
Step 3/6 : ADD /* /usr/src/
......
[root@master ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
yanghaixx/apache latest ebd6cbf9d275 20 seconds ago 702MB
yanghaixx/nginx v2 8253e25bc4b2 4 days ago 578MB
[root@master ~]# docker push yanghaixx/apache
Using default tag: latest
The push refers to repository [docker.io/yanghaixx/apache]
791c489fb2db: Pushed
2220934d50a1: Pushed
74ddd0ec08fa: Mounted from yanghaixx/nginx
latest: digest: sha256:a1cff9297a739e3c4adf350202d04f0e15315535dd2fbba1fbee7c1f08c20b67 size: 954
[root@master ~]# docker run -itd --name httpd -p 80:80 ebd6cbf9d275
4c8aaa66407cce876ec8392e57143509a06f10e13661acd9de19f04bd34c850f