dockerfile制作apache镜像

本文档详细介绍了如何从头开始构建Apache HTTP服务器的Docker镜像,包括准备必要的源代码文件,编写Dockerfile,构建镜像,启动容器,并最终将镜像推送到Docker Hub。步骤包括配置Apache的编译选项,设置端口映射,以及通过浏览器验证服务运行。
摘要由CSDN通过智能技术生成

1. 结构目录

[root@localhost ~]# tree apache/
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@localhost ~]# 

2. 编写dockerfile文件

[root@localhost ~]# cat apache/dockerfile 
FROM centos 

LABEL MAINTAINER='pengyudong 3367865314@qq.com' 

ADD  files/* /usr/src/   
    
WORKDIR /usr/src/       
     
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 -j $(grep 'processor' /proc/cpuinfo | wc -l) && make install    
      
EXPOSE 80     
                    
CMD  ["/usr/local/apache/bin/apachectl","-D","FOREGROUND"]    
[root@localhost ~]# 

3. 构建镜像

[root@localhost ~]# docker build -t pengyudong/httpd:latest  /apache/

4. 基于新镜像创建容器

[root@localhost ~]# docker run --name httpd -dit -p 80:80 pengyudong/httpd:latest 
1b7e14ac0a582266e91e5aea09db1538bf07cce695158c413d96fecc89d9d7f3
[root@localhost ~]# docker ps 
CONTAINER ID   IMAGE                     COMMAND                  CREATED         STATUS         PORTS                               NAMES
1b7e14ac0a58   pengyudong/httpd:latest   "/usr/local/apache/b…"   5 seconds ago   Up 4 seconds   0.0.0.0:80->80/tcp, :::80->80/tcp   httpd
[root@localhost ~]# docker exec -it httpd /bin/bash
[root@1b7e14ac0a58 src]# ss -antl
State       Recv-Q      Send-Q           Local Address:Port            Peer Address:Port      Process      
LISTEN      0           128                    0.0.0.0:80                   0.0.0.0:*           

5. 浏览器访问

在这里插入图片描述

6. 上传到docker hub

[root@localhost ~]# docker login 
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: pengyudong
Password: 
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
[root@localhost ~]# docker push pengyudong/httpd
pengyudong/httpd         pengyudong/httpd:latest  pengyudong/httpd:v1      
[root@localhost ~]# docker push pengyudong/httpd:latest 
The push refers to repository [docker.io/pengyudong/httpd]
32395be7e84b: Pushed 
e00e9754c5d3: Pushed 
74ddd0ec08fa: Mounted from library/centos 
latest: digest: sha256:8e10aff5802691ba0a3989d2c5d84d830a9f75f8d42d26053ec4a46694e67504 size: 954
[root@localhost ~]# 

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

彭宇栋

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值