目 录CONTENT

文章目录

dockerfile 安装apache服务

ZiChen D
2021-12-09 / 0 评论 / 0 点赞 / 289 阅读 / 4,560 字 / 正在检测是否收录...

使用Dockerfile方式安装apache服务

编写Dockerfile安装apache

# This dockerfile uses the centos image
# VERSION 0.1
# 安装包需自己手动提供,下载链接:http://dlcdn.apache.org
# 安装包放在与Dockerfile文件同级目录下

# 基础镜像
FROM centos

# 维护者信息
LABEL MAINTAINER=dzc@163.com

# 设置变量
ENV PG_route /usr/local

# 安装apache
ADD apr-1.7.0.tar.gz $PG_route
ADD apr-util-1.6.1.tar.gz $PG_route
ADD httpd-2.4.48.tar.gz $PG_route

RUN yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make && \
    yum -y groups mark install 'Development Tools' && \
    sed -i 's/$RM "$cfgfile"/# $RM "$cfgfile"/g' $PG_route/apr-1.7.0/configure && \
    cd $PG_route/apr-1.7.0 && ./configure --prefix=$PG_route/apr && make && make install && \
    cd $PG_route/apr-util-1.6.1 && ./configure --prefix=$PG_route/apr-util --with-apr=$PG_route/apr && make && make install && \
    cd $PG_route/httpd-2.4.48 && ./configure --prefix=$PG_route/apache \
    --enable-so \
    --enable-ssl \
    --enable-cgi \
    --enable-rewrite \
    --with-zlib \
    --with-pcre \
    --with-apr=$PG_route/apr \
   --with-apr-util=$PG_route/apr-util/ \
    --enable-modules=most \
    --enable-mpms-shared=all \
    --with-mpm=prefork && make && make install && \
    echo 'export PATH=$PG_route/apache/bin:$PATH' > /etc/profile.d/httpd.sh && \
    source /etc/profile.d/httpd.sh && \
    ln -s $PG_route/apache/include/ /usr/include/httpd && \
    sed -i 's/#ServerName www.example.com:80/ServerName 172.17.0.2:80/g' $PG_route/apache/conf/httpd.conf
    rm -rf $PG_route/apr-1.7.0 $PG_route/apr-util-1.6.1 $PG_route/httpd-2.4.48

# 开放端口
EXPOSE 80

# 启动apache
CMD $PG_route/apache/bin/apachectl -D FOREGROUND

创建镜像

[root@localhost apache_dockerfile]# docker build -t apache:v0.2 .
Sending build context to Docker daemon  11.07MB
Step 1/9 : FROM centos
 ---> 5d0da3dc9764
Step 2/9 : LABEL MAINTAINER=dzc@163.com
 ---> Using cache
 ---> 5e156de7cf8f
Step 3/9 : ENV PG_route /usr/local
 ---> Using cache
 ---> 039846e97055
Step 4/9 : ADD apr-1.7.0.tar.gz $PG_route
 ---> Using cache
 ---> 5bcee0f3077d
Step 5/9 : ADD apr-util-1.6.1.tar.gz $PG_route
 ---> Using cache
 ---> 944ea87d7268
Step 6/9 : ADD httpd-2.4.48.tar.gz $PG_route
 ---> Using cache
 ---> 0e6d35cae454
Step 7/9 : RUN yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make &&     yum -y groups mark install 'Development Tools' &&     sed -i 's/$RM "$cfgfile"/# $RM "$cfgfile"/g' $PG_route/apr-1.7.0/configure &&     cd $PG_route/apr-1.7.0 && ./configure --prefix=$PG_route/apr && make && make install &&     cd $PG_route/apr-util-1.6.1 && ./configure --prefix=$PG_route/apr-util --with-apr=$PG_route/apr && make && make install &&     cd $PG_route/httpd-2.4.48 && ./configure --prefix=$PG_route/apache     --enable-so     --enable-ssl     --enable-cgi     --enable-rewrite     --with-zlib     --with-pcre     --with-apr=$PG_route/apr     --with-apr-util=$PG_route/apr-util/     --enable-modules=most     --enable-mpms-shared=all     --with-mpm=prefork && make && make install &&     echo 'export PATH=$PG_route/apache/bin:$PATH' > /etc/profile.d/httpd.sh &&     source /etc/profile.d/httpd.sh &&     ln -s $PG_route/apache/include/ /usr/include/httpd &&     sed -i 's/#ServerName www.example.com:80/ServerName 172.17.0.2:80/g' $PG_route/apache/conf/httpd.conf
 ---> Using cache
 ---> 3d307f9e1c10
Step 8/9 : EXPOSE 80
 ---> Using cache
 ---> c050f8317736
Step 9/9 : CMD $PG_route/apache/bin/apachectl start -D FOREGROUND
 ---> Running in 9cdd79e3c684
Removing intermediate container 9cdd79e3c684
 ---> 50b062204837
Successfully built 50b062204837
Successfully tagged apache:v0.2

上传镜像

[root@localhost apache_dockerfile]# docker push dengzichen/apache:v0.6 
The push refers to repository [docker.io/dengzichen/apache]
12196ce17415: Layer already exists 
9f614c4c3b3a: Layer already exists 
416fe483dd41: Pushed 
1fd673786f71: Layer already exists 
74ddd0ec08fa: Layer already exists 
v0.6: digest: sha256:9b346e13d3195b703468663d25e49895d9ae72152faf169094bd7c2205e0b189 size: 1374

使用镜像创建容器

[root@localhost ~]# docker run --rm -itd -p 80:80 apache:v0.2 
a0bd227118c1ab800de23864b85ee4cb84cf21f45d957a4cccbb963208540c52
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE         COMMAND                  CREATED         STATUS         PORTS                               NAMES
a0bd227118c1   apache:v0.2   "/bin/sh -c '$PG_rou…"   3 seconds ago   Up 2 seconds   0.0.0.0:80->80/tcp, :::80->80/tcp   funny_hermann

网页测试

0

评论区