[root@6a41da7c72b8 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 TimeTimeTime Current
Dload Upload Total Spent Left Speed
1002495100249500127940--:--:----:--:----:--:--12794
[root@6a41da7c72b8 yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@6a41da7c72b8 yum.repos.d]# ls
CentOS-Base.repo
[root@6a41da7c72b8 yum.repos.d]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@6a41da7c72b8 yum.repos.d]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@6a41da7c72b8 yum.repos.d]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
[root@6a41da7c72b8 yum.repos.d]# yum clean all
[root@6a41da7c72b8 yum.repos.d]# yum makecache
[root@6a41da7c72b8 yum.repos.d]# yum list all
6. 安装编译器
[root@6a41da7c72b8 ~]# yum -y install vim make gcc gcc-c++
7. 编译安装apr,修改apr配置文件
安装apr
[root@6a41da7c72b8 ~]# cd /usr/src/muchen/
[root@6a41da7c72b8 muchen]# ls
apr-1.7.0 apr-util-1.6.1 httpd-2.4.53
apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.53.tar.gz
[root@6a41da7c72b8 muchen]# cd apr-1.7.0
[root@677331c49a2b apr-1.7.0]# vim configure
[root@677331c49a2b apr-1.7.0]# cat configure|grep cfgfile
cfgfile=${ofile}T
trap "$RM \"$cfgfile\"; exit 1"1215
# $RM "$cfgfile"//将此行注释掉
[root@677331c49a2b apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@677331c49a2b apr-1.7.0]# nproc
4
[root@677331c49a2b apr-1.7.0]# make -j 4
[root@677331c49a2b apr-1.7.0]# make install
8. 编译安装apr-util
[root@677331c49a2b apr-1.7.0]# cd ..
[root@677331c49a2b src]# cd apr-util-1.6.1
[root@677331c49a2b apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@677331c49a2b apr-util-1.6.1]# make -j 4
xml/apr_xml.c:35:10: fatal error: expat.h: No such file or directory//expat.h:没有这样的文件或目录
[root@6a41da7c72b8 apr-util-1.6.1]# yum -y install expat-devel
重新编译
[root@6a41da7c72b8 muchen]# tar xf apr-util-1.6.1.tar.gz
[root@6a41da7c72b8 muchen]# cd apr-util-1.6.1
[root@6a41da7c72b8 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr
[root@6a41da7c72b8 apr-util-1.6.1]# make -j 4
9. 编译安装httpd
[root@6a41da7c72b8 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=worker//用worker模式
configure:error: pcre(2)-config for libpcre not found. PCRE is required and available from http://pcre.org/pcre不可用
[root@6a41da7c72b8 httpd-2.4.53]# yum -y install pcre-devel
[root@6a41da7c72b8 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=worker //再次编译
checking for OpenSSL... checking for user-provided OpenSSL base directory... none
checking for OpenSSL version >=0.9.8a... FAILED
[root@6a41da7c72b8 httpd-2.4.53]# yum -y install openssl-[root@6a41da7c72b8 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=worker
[root@6a41da7c72b8 httpd-2.4.53]# make -j 4
[root@6a41da7c72b8 httpd-2.4.53]# make install
二. 第一种方法 编写脚本
1. 编写启动脚本
[root@6a41da7c72b8 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
[root@6a41da7c72b8 ~]# cd /
[root@6a41da7c72b8 /]# ls
bin etc lib lost+found mnt proc run srv tmp var
dev home lib64 media opt root sbin sys usr
[root@6a41da7c72b8 /]# vim entrypoint.sh
[root@6a41da7c72b8 /]# cat entrypoint.sh
#!/bin/bash/usr/local/apache/bin/httpd &&sleep5d//休息5天
[root@6a41da7c72b8 /]# chmod +x entrypoint.sh
[root@6a41da7c72b8 /]# ls -l entrypoint.sh
-rwxr-xr-x. 1 root root 53 Apr 2708:09 entrypoint.sh
[root@6a41da7c72b8 /]#
[root@6a41da7c72b8 /]# ./entrypoint.sh
AH00558: httpd: Could not reliably determine the server's fully qualified domain name,using172.17.0.2. Set the 'ServerName' directive globally to suppress this message
httpd (pid 36986) already running
^C
[root@6a41da7c72b8 /]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 01280.0.0.0:800.0.0.0:*
[root@6a41da7c72b8 /]# ./entrypoint.sh
AH00558: httpd: Could not reliably determine the server's fully qualified domain name,using172.17.0.2. Set the 'ServerName' directive globally to suppress this message
httpd (pid 36986) already running
[root@SYL4 ~]# docker commit -a 'xiaoyinguhong <2807689558@qq.com>' -c 'CMD ["/entrypoint.sh"]' -p c1 xiaoyinguhong/httpd:2060.2
sha256:cb99f86de5ef6bb6da6cc6cfaf65c44cf272d4956b5afee7cee9942f68d8fcd2
[root@SYL4 ~]#
[root@SYL4 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
xiaoyinguhong/httpd 2060.2 cb99f86de5ef 34 seconds ago 720MB
xiaoyinguhong/httpd 2060.106493b8526eb 24 hours ago 1.24MB
httpd 2.4.53 c30a46771695 6 days ago 144MB
busybox latest beae173ccac6 3 months ago 1.24MB
httpd latest dabbfbe0c57b 4 months ago 144MB
centos latest 5d0da3dc9764 7 months ago 231MB
4. 运行制作的镜像
[root@SYL4 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 01280.0.0.0:220.0.0.0:*
LISTEN 0128 [::]:22 [::]:*
[root@SYL4 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6a41da7c72b8 centos "/bin/bash"3 hours ago Up 45 minutes c1
[root@SYL4 ~]# docker run-d --name web -p 80:80 xiaoyinguhong/httpd:2060.23a5a452f9df3d565cd3a3816d947778a0d97f5b2b74ac953ed6a66a11dc1bc48
[root@SYL4 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3a5a452f9df3 xiaoyinguhong/httpd:2060.2"/entrypoint.sh"17 seconds ago Up 13 seconds 0.0.0.0:80->80/tcp,:::80->80/tcp web
6a41da7c72b8 centos "/bin/bash"3 hours ago Up 45 minutes c1
[root@SYL4 ~]#
5. 访问成功
6. 删除镜像中不需要的文件,再次制作镜像
删除gcc make cache目录下,安装包文件
[root@SYL4 ~]# docker commit -a 'xiaoyinguhong <2807689558@qq.com>' -c 'CMD ["/entrypoint.sh"]' -p c1 xiaoyinguhong/httpd:2060.3
sha256:16acf7cb66642ea345dfad0a5066e26df7695c3f687cdd9079dfc3e11c20e71d
[root@SYL4 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
xiaoyinguhong/httpd 2060.316acf7cb6664 11 seconds ago 383MB
xiaoyinguhong/httpd 2060.26d21fe0560e3 23 minutes ago 720MB
xiaoyinguhong/httpd 2060.106493b8526eb 25 hours ago 1.24MB
httpd 2.4.53 c30a46771695 7 days ago 144MB
busybox latest beae173ccac6 3 months ago 1.24MB
httpd latest dabbfbe0c57b 4 months ago 144MB
centos latest 5d0da3dc9764 7 months ago 231MB
[root@SYL4 ~]#
7. 上传镜像
[root@SYL4 ~]# docker push xiaoyinguhong/httpd:2060.3
The push refers to repository [docker.io/xiaoyinguhong/httpd]
403b3ff115cc: Pushed
74ddd0ec08fa: Mounted from library/centos
2060.3: digest: sha256:b977c13ef08a9068d5c853996038d98aa224575aca112ef90c75896108ea98c4 size:741
[root@SYL4 ~]#
第二台192.168.232.129
[root@SYL2 ~]# ls
httpd.tar mysql
[root@SYL2 ~]# docker load -i httpd.tar
74ddd0ec08fa: Loading layer 238.6MB/238.6MB
bcd1297cdc59: Loading layer 501.4MB/501.4MB
Loaded image: xiaoyinguhong/httpd:2060.2
[root@SYL2 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
xiaoyinguhong/httpd 2060.26d21fe0560e3 46 minutes ago 720MB
xiaoyinguhong/httpd 2060.106493b8526eb 26 hours ago 1.24MB
xiaoyinguhong/busybox 2060.1 aa5b7f970c0c 27 hours ago 1.24MB
[root@SYL2 ~]#
三. 第二种 设置在前台运行
1. 设置在前台运行
[root@6a41da7c72b8 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
[root@6a41da7c72b8 ~]# /usr/local/apache/bin/httpd -DFOREGROUND