使用dockerfile制作apache镜像
[root@localhost ~]# mkdir /apache/
[root@localhost ~]# cd /apache
[root@localhost apache]# mkdir files
# 将安装包放在files下
[root@localhost apache]# ls files
apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.49.tar.gz
[root@localhost ~]# vim /apache/dockerfile
# This dockerfile uses the ubuntu image
# VERSION 2 - EDITION 1
# Author: seancheng
# Command format: Instruction [arguments / command] ...
# 第一行必须指定基于的基础镜像
FROM centos
# 维护者信息
LABEL MAINTAINER='neawalke 123456789@qq.com'
ENV httpd_version 2.4.48
# 镜像操作指令
ADD https://archive.apache.org/dist/apr/apr-1.6.5.tar.gz /usr/src/
ADD https://archive.apache.org/dist/apr/apr-util-1.6.1.tar.gz /usr/src/
ADD https://archive.apache.org/dist/httpd/httpd-${httpd_version}.tar.gz /usr/src/
WORKDIR /usr/src/
RUN yum -y install openssl-devel pcre-devel pcre expat-devel libtool gcc gcc-c++ make && \
tar xf apr-1.6.5.tar.gz -C /usr/src && \
tar xf apr-util-1.6.1.tar.gz -C /usr/src && \
tar xf httpd-${httpd_version}.tar.gz -C /usr/src && \
cd apr-1.6.5 && \
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_version} && \
./configure --prefix=/usr/local/httpd \
--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
EXPOSE 80
# 容器启动时默认要执行的指令
CMD ["-D","FOREGROUND"]
ENTRYPOINT ["/usr/local/httpd/bin/apachectl"]
构建镜像
[root@localhost ~]# docker build -t neawalke/httpd:latest /apache/
Sending build context to Docker daemon 11.08MB
Step 1/7 : FROM centos
---> 5d0da3dc9764
Step 2/7 : LABEL MAINTAINER='neawalke 2563603655@qq.com'
---> Running in d1f55fcf60b9
Removing intermediate container d1f55fcf60b9
---> 66611802941f
Step 3/7 : ADD files/* /usr/src/
---> 26aa649616f3
Step 4/7 : WORKDIR /usr/src/
---> Running in 9cc6b3e77969
Removing intermediate container 9cc6b3e77969
---> 574d4c19f67b
Step 5/7 : RUN yum -y install openssl-devel pcre-devel pcre expat-devel libtool gcc gcc-c++ make && cd 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-2.4.49 && ./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
---> Running in aa70368fbc6d
Removing intermediate container aa70368fbc6d
---> 5ec06d0d06a8
Step 6/7 : EXPOSE 80
---> Running in f6d50f2e2558
Removing intermediate container f6d50f2e2558
---> 5a0e2eb67115
Step 7/7 : CMD ["/usr/local/apache/bin/apachectl","-D","FOREGROUND"]
---> Running in 13bd6510063b
Removing intermediate container 13bd6510063b
---> a88d5450bfd2
Successfully built a88d5450bfd2
Successfully tagged syblyw0806/httpd:latest
[root@localhost ~]# docker push neawalke/httpd:latest
[root@localhost apache]# docker run -it --rm neawalke/httpd:latest
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
[root@localhost ~]# curl 172.17.0.2
<html><body><h1>It works!</h1></body></html>