在docker安装编译apache

[root@slave ~]# docker run -it --name b1 centos /bin/bash
[root@7b38cd0fcb24 /]# cd
[root@7b38cd0fcb24 ~]# cd /etc/yum.repos.d/
[root@7b38cd0fcb24 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@7b38cd0fcb24 yum.repos.d]# rm -rf *
[root@7b38cd0fcb24 yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2495  100  2495    0     0  11713      0 --:--:-- --:--:-- --:--:-- 11768
[root@7b38cd0fcb24 yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@7b38cd0fcb24 yum.repos.d]# ls
CentOS-Base.repo
[root@7b38cd0fcb24 yum.repos.d]# dnf clean all
Failed to set locale, defaulting to C.UTF-8
0 files removed
[root@slave data]# wget https://mirrors.aliyun.com/apache/apr/apr-1.6.5.tar.gz
--2022-08-08 22:17:06--  https://mirrors.aliyun.com/apache/apr/apr-1.6.5.tar.gz
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 58.49.248.226, 180.101.197.238, 180.101.199.242, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|58.49.248.226|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1073556 (1.0M) [application/octet-stream]
Saving to: ‘apr-1.6.5.tar.gz’

apr-1.6.5.tar.gz      100%[=========================>]   1.02M  --.-KB/s    in 0.07s   

2022-08-08 22:17:06 (13.9 MB/s) - ‘apr-1.6.5.tar.gz’ saved [1073556/1073556]
[root@7b38cd0fcb24 yum.repos.d]# dnf makecache
Failed to set locale, defaulting to C.UTF-8
CentOS-8.5.2111 - Base - mirrors.aliyun.com                          494 kB/s | 4.6 MB     00:09    
CentOS-8.5.2111 - Extras - mirrors.aliyun.com                         39 kB/s |  10 kB     00:00    
CentOS-8.5.2111 - AppStream - mirrors.aliyun.com                     1.3 MB/s | 8.4 MB     00:06    
Metadata cache created.
[root@7b38cd0fcb24 yum.repos.d]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:00:28 ago on Wed Aug 10 01:21:40 2022.
epel-release-latest-8.noarch.rpm                                      98 kB/s |  24 kB     00:00    
Dependencies resolved.
=====================================================================================================
 Package                   Architecture        Version               Repository                 Size
=====================================================================================================
Installing:
 epel-release              noarch              8-16.el8              @commandline               24 k

Transaction Summary
=====================================================================================================
Install  1 Package

Total size: 24 k
Installed size: 34 k
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                             1/1 
  Installing       : epel-release-8-16.el8.noarch                                                1/1 
  Running scriptlet: epel-release-8-16.el8.noarch                                                1/1 
Many EPEL packages require the CodeReady Builder (CRB) repository.
It is recommended that you run /usr/bin/crb enable to enable the CRB repository.

  Verifying        : epel-release-8-16.el8.noarch                                                1/1 

Installed:
  epel-release-8-16.el8.noarch                                                                       

Complete!

[root@7b38cd0fcb24 ~]# dnf -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ wget vim make 
[root@7b38cd0fcb24 ~]# dnf -y groups mark install 'Development Tools' 
[root@7b38cd0fcb24~]# useradd -r -M -s /sbin/nologin apache 
[root@7b38cd0fcb24 ~]# id apache 
uid=998(apache) gid=996(apache) groups=996(apache)

[root@7b38cd0fcb24 ~]# wget https://downloads.apache.org/apr/apr-1.7.0.tar.gz https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz https://downloads.apache.org/httpd/httpd-2.4.54.tar.gz 
[root@7b38cd0fcb24 ~]# tar -xf apr-1.7.0.tar.gz 
[root@7b38cd0fcb24 ~]# tar -xf apr-util-1.6.1.tar.gz 
[root@7b38cd0fcb24 ~]# tar -xf httpd-2.4.54.tar.gz 
[root@7b38cd0fcb24 ~]#cd apr-1.7.0/
[root@7b38cd0fcb24  apr-1.7.0]# vim configure 
 $RM "$cfgfile" 
[root@7b38cd0fcb24  apr-1.7.0]# ./configure --prefix=/usr/local/apr 
[root@7b38cd0fcb24  apr-1.7.0]# make 
[root@7b38cd0fcb24  apr-1.7.0]# make install

[root@7b38cd0fcb24 apr-1.7.0]# cd ../apr-util-1.6.1/ 
[root@7b38cd0fcb24 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr 
[root@7b38cd0fcb24 apr-util-1.6.1]# make 
[root@7b38cd0fcb24 apr-util-1.6.1]# make install
[root@7b38cd0fcb24 apr-util-1.6.1]# cd 
[root@7b38cd0fcb24 ~]# cd httpd-2.4.54/ 

[root@7b38cd0fcb24 httpd-2.4.54]# ./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@7b38cd0fcb24 httpd-2.4.54]# make 
[root@7b38cd0fcb24 httpd-2.4.54]# make install

[root@7b38cd0fcb24 ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh 
[root@7b38cd0fcb24 ~]# source /etc/profile.d/httpd.sh 
[root@7b38cd0fcb24 ~]# which httpd 
/usr/local/apache/bin/httpd 
[root@7b38cd0fcb24 ~]# ln -sv /usr/local/apache/include /usr/include/apache 
'/usr/include/apache' -> '/usr/local/apache/include' 
[root@7b38cd0fcb24 ~]# cd /usr/local/apache/conf/ 
[root@7b38cd0fcb24 conf]# vim httpd.conf 
ServerName www.example.com:80 
[root@7b38cd0fcb24 apache]# ./bin/httpd 
[root@7b38cd0fcb24 apache]# 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:* 
[root@7b38cd0fcb24 apache]# pkill httpd 
[root@7b38cd0fcb24 apache]# cd / 
 [root@7b38cd0fcb24 /]# vim mr.sh  
 #!/bin/bash /usr/local/apache/bin/httpd && sleep 5d 
 [root@7b38cd0fcb24 /]# chmod +x mr.sh 
 [root@7b38cd0fcb24 /]# 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:*
[root@slave ~]# docker commit -a 'mr <mr.com>' -c 'CMD ["/mr.sh"]' -p b1 marui123/httpd:1.0
sha256:c8317559a2a29a52b7aceffb31fcb86c3480a5c18940b9ecd382838753eca04d
[root@slave ~]# docker images
REPOSITORY       TAG       IMAGE ID       CREATED          SIZE
marui123/httpd   1.0       c8317559a2a2   15 seconds ago   778MB
busybox          latest    beae173ccac6   7 months ago     1.24MB
httpd            latest    dabbfbe0c57b   7 months ago     144MB
centos           latest    5d0da3dc9764   10 months ago    231MB
[root@slave ~]# 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: marui123
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@slave ~]# docker push marui123/httpd:1.0
The push refers to repository [docker.io/marui123/httpd]
f847afebd469: Pushed 
74ddd0ec08fa: Mounted from library/centos 
1.0: digest: sha256:fd188dc336ba99b46a7eae1cc1c380797bcb27262f82778ec3392a3c3f550503 size: 742
[root@slave ~]# 

posted @   溜溜威  阅读(54)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示