[root@cxr ~]# mkdir -p /opt/apache/files
[root@cxr ~]# cd /opt/apache/
[root@cxr apache]# touch Dockerfile
[root@cxr apache]# ls
dockerfile files
[root@cxr apache]# tree
.
├── Dockerfile
└── files
├── apr-1.7.0.tar.gz
├── apr-util-1.6.1.tar.gz
└── httpd-2.4.53.tar.gz
[root@cxr dockerfile]# vim Dockerfile
FROM centos //使用centos镜像
LABEL MAINTAINER='chen [email protected]' //打标签,你的基本信息
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-vault-8.5.2111.repo && \
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo && \
yum clean all && \
yum makecache && \
useradd -r -M -s /sbin/nologin apache && \
yum -y install openssl-devel pcre-devel expat-devel libtool bzip2 gcc gcc-c++ make && \
yum -y groups mark install "Development Tools" &&\
tar xf /usr/src/apr-1.7.0.tar.gz && \
tar xf /usr/src/apr-util-1.6.1.tar.gz && \
tar xf /usr/src/httpd-2.4.53.tar.gz && \
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.53 && \
./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
EXPOSE 80 //写你要暴露的端口号一般只有80端口
VOLUME ["/usr/local/apache/htdocs/"] //定义宿主机或其他容器的挂载点
CMD ["/usr/local/apache/bin/apachectl","-D","FOREGROUND"] 启动容器让apache在默认在前台运行
[root@cxr apache]# docker build -t chen1544060135/httpd:v0.1 /opt/apache/
[root@cxr apache]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
chen1544060135/httpd v0.1 b81ac90ec490 53 minutes ago 717MB
[root@cxr apache]# docker run -d -P --name httpd chen1544060135/httpd:v0.1
[root@cxr apache]# docker port httpd
80/tcp -> 0.0.0.0:49153
80/tcp -> :::49153
[root@cxr apache]# docker push chen1544060135/httpd:v0.1
docker push chen1544060135/httpd:v0.1
394497b2c62e: Pushed
394497b2c62e: Pushing 142.4MB/474.7MB
de8d6a4797f0: Layer already exists
v0.1: digest: sha256:1818af70b18edced0b9636fb5337bf67196276c30400ee68c7b7fb36a2c17e55 size: 954
[root@cxr apache]#