使用docker编译安装apache

[root@localhost ~]# docker ps
CONTAINER ID   IMAGE      COMMAND       CREATED          STATUS          PORTS     NAMES
91e6baae2701   centos:8   "/bin/bash"   41 minutes ago   Up 41 minutes

[root@localhost ~]# docker commit -p -c 'CMD ["/bin/bash","/start.sh"]' 91e6baae2701 mingzi/httpd:v1.0
sha256:62f892851ea412abdc1eb8fc2da60ebfc001bd3ed8fe8db41ee46706367844ce

先拉一个centos的镜像

[root@localhost ~]# docker pull centos:8
8: Pulling from library/centos
a1d0c7532777: Pull complete 
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for centos:8
docker.io/library/centos:8
[root@localhost ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
nginx        latest    fa5269854a5e   6 days ago     142MB
httpd        2.4.53    c30a46771695   6 days ago     144MB
httpd        latest    c30a46771695   6 days ago     144MB
busybox      latest    beae173ccac6   3 months ago   1.24MB
centos       8         5d0da3dc9764   7 months ago   231MB

用centos生成一个容器进去

[root@localhost ~]#  docker run -it --name httpd centos:8 /bin/bash
[root@3806b7d23cd0 /]# cd /etc/yum.repos.d/
[root@3806b7d23cd0 yum.repos.d]# ls
CentOS-Linux-AppStream.repo	     CentOS-Linux-FastTrack.repo
CentOS-Linux-BaseOS.repo	     CentOS-Linux-HighAvailability.repo
CentOS-Linux-ContinuousRelease.repo  CentOS-Linux-Media.repo
CentOS-Linux-Debuginfo.repo	     CentOS-Linux-Plus.repo
CentOS-Linux-Devel.repo		     CentOS-Linux-PowerTools.repo
CentOS-Linux-Extras.repo	     CentOS-Linux-Sources.repo

配置新的源

[root@3806b7d23cd0 yum.repos.d]# rm -rf *
[root@3806b7d23cd0 yum.repos.d]# ls
[root@3806b7d23cd0 yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@3806b7d23cd0 yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@3806b7d23cd0 yum.repos.d]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@3806b7d23cd0 yum.repos.d]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@3806b7d23cd0 yum.repos.d]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
[root@3806b7d23cd0 yum.repos.d]# yum clean all
[root@3806b7d23cd0 yum.repos.d]# yum makecache
[root@3806b7d23cd0 yum.repos.d]# ls
CentOS-Base.repo   epel-testing-modular.repo  epel.repo
epel-modular.repo  epel-testing.repo

进入容器编译安装apache

[root@localhost ~]# docker cp httpd-2.4.53.tar.gz httpd:/usr/src/
[root@localhost ~]# docker cp apr-util-1.6.1.tar.gz httpd:/usr/src/
[root@localhost ~]# docker cp apr-1.7.0.tar.gz httpd:/usr/src/
//复制到usr

[root@91e6baae2701 /]# ls /usr/src/
apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  debug	httpd-2.4.53.tar.gz  kernels

[root@91e6baae2701 /]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make
//安装他的依赖包

[root@91e6baae2701 /]# useradd -r -M -s /sbin/nologin apache
//创建用户

[root@91e6baae2701 src]# tar -xf apr-1.7.0.tar.gz
[root@91e6baae2701 src]# cd apr-1.7.0
[root@91e6baae2701 apr-1.7.0]# vi configure

    cfgfile=${ofile}T
    trap "$RM \"$cfgfile\"; exit 1" 1 2 15

//解压注释
[root@91e6baae2701 apr-1.7.0]# ./configure --prefix=/usr/local/apr
//安装

[root@91e6baae2701 apr-1.7.0]# cd ..
[root@91e6baae2701 src]# tar -xf apr-util-1.6.1.tar.gz
[root@91e6baae2701 src]# cd apr-util-1.6.1
[root@91e6baae2701 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
//编译安装


[root@91e6baae2701 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

[root@91e6baae2701 httpd-2.4.53]# make 
[root@91e6baae2701 httpd-2.4.53]# make install

设置他的头文件

 echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/apache.sh
[root@91e6baae2701 httpd-2.4.53]# source /etc/profile.d/apache.sh

[root@91e6baae2701 apache]# ln -s /usr/local/apache/include/ /usr/include/apache

关闭防火墙

[root@91e6baae2701 apache]# systemctl disable --now firewalld
Failed to disable unit, unit firewalld.service does not exist.
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

启动apache

[root@91e6baae2701 apache]# ss -ant
State   Recv-Q   Send-Q     Local Address:Port     Peer Address:Port  Process  
LISTEN  0        128              0.0.0.0:80            0.0.0.0:*     

制作httpd镜像

[root@localhost ~]# docker commit -p -c 'CMD ["/bin/bash","/start.sh"]' 91e6baae2701 mingzi/httpd:v1.0
sha256:62f892851ea412abdc1eb8fc2da60ebfc001bd3ed8fe8db41ee46706367844ce
[root@localhost ~]#  docker images
REPOSITORY     TAG       IMAGE ID       CREATED          SIZE
mingzi/httpd   v1.0      62f892851ea4   56 seconds ago   774MB

对镜像进行验证

root@localhost ~]# docker ps
CONTAINER ID   IMAGE      COMMAND       CREATED          STATUS          PORTS     NAMES
91e6baae2701   centos:8   "/bin/bash"   45 minutes ago   Up 45 minutes             httpd
[root@localhost ~]# docker stop httpd
httpd
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[root@localhost ~]# docker run -dit -p 80:80 --name web mingzi/httpd:v1.0 /bin/bash
1763ee9f89601d886dabab9ad6c2898fb7f6dba4b022d1e3aec231bb962d1e67

[root@localhost ~]# docker ps
CONTAINER ID   IMAGE               COMMAND       CREATED         STATUS         PORTS                               NAMES
1763ee9f8960   mingzi/httpd:v1.0   "/bin/bash"   3 minutes ago   Up 3 minutes   0.0.0.0:80->80/tcp, :::80->80/tcp   web

​​​​​​​

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值