在centos镜像中编译安装httpd
//进入镜像下载阿里源
[root@localhost ~]# docker run -it --name httpd centos
[root@daa4b5196b67 /]# cd /etc/yum.repos.d/
[root@daa4b5196b67 yum.repos.d]# rm -rf *
[root@daa4b5196b67 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 9633 0 --:--:-- --:--:-- --:--:-- 9596
[root@daa4b5196b67 yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@daa4b5196b67 yum.repos.d]# yum makecache
Failed to set locale, defaulting to C.UTF-8
CentOS-8.5.2111 - Base - mirrors.aliyun.com 1.1 MB/s | 4.6 MB 00:04
CentOS-8.5.2111 - Extras - mirrors.aliyun.com 45 kB/s | 10 kB 00:00
CentOS-8.5.2111 - AppStream - mirrors.aliyun.com 805 kB/s | 8.4 MB 00:10
Metadata cache created.
//安装软件开发包
[root@daa4b5196b67 ~]# yum groups mark install 'Development Tools'
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:02:07 ago on Tue Aug 9 02:16:44 2022.
Dependencies resolved.
=====================================================================================================================================
Package Architecture Version Repository Size
=====================================================================================================================================
Installing Groups:
Development Tools
Transaction Summary
=====================================================================================================================================
Is this ok [y/N]: yes
Complete!
//创建用户
[root@daa4b5196b67 ~]# useradd -r -M -s /sbin/nologin apache
[root@daa4b5196b67 ~]# id apache
uid=998(apache) gid=996(apache) groups=996(apache)
//安装依赖包
[root@daa4b5196b67 ~]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make wget vim
......
//下载和安装httpd apr以及apr-util
[root@daa4b5196b67 ~]# 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@daa4b5196b67 ~]# ls
anaconda-ks.cfg anaconda-post.log apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.54.tar.gz original-ks.cfg
[root@daa4b5196b67 ~]# tar xf apr-1.7.0.tar.gz
[root@daa4b5196b67 ~]# tar xf apr-util-1.6.1.tar.gz
[root@daa4b5196b67 ~]# ls
anaconda-ks.cfg apr-1.7.0 apr-util-1.6.1 httpd-2.4.54.tar.gz
anaconda-post.log apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz original-ks.cfg
[root@daa4b5196b67 ~]# cd apr-1.7.0
apr-1.7.0/ apr-1.7.0.tar.gz
[root@daa4b5196b67 ~]# cd apr-1.7.0/
[root@daa4b5196b67 apr-1.7.0]# vim configure
cfgfile=${ofile}T
trap "$RM \"$cfgfile\"; exit 1" 1 2 15
#$RM "$cfgfile" //将此行加上注释,或者删除此行
cat <<_LT_EOF >> "$cfgfile"
#! $SHELL
[root@daa4b5196b67 apr-1.7.0]# ./configure --prefix=/usr/local/apr
......
[root@daa4b5196b67 apr-1.7.0]# make && make install
......
[root@daa4b5196b67 ~]# cd apr-util-1.6.1
[root@daa4b5196b67 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
......
[root@daa4b5196b67 apr-util-1.6.1]# make && make install
......
[root@daa4b5196b67 ~]# tar xf httpd-2.4.54.tar.gz
[root@daa4b5196b67 ~]# cd httpd-2.4.54
[root@daa4b5196b67 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@daa4b5196b67 httpd-2.4.54]# make && make install
......
[root@daa4b5196b67 ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@daa4b5196b67 ~]# source /etc/profile.d/httpd.sh
[root@daa4b5196b67 ~]# which httpd
/usr/local/apache/bin/httpd
[root@daa4b5196b67 ~]# ln -s /usr/local/apache/include/ /usr/include/httpd
[root@daa4b5196b67 ~]# vim /etc/man_db.conf
MANDATORY_MANPATH /usr/local/apache/man
[root@daa4b5196b67 ~]# vim /entrypoint.sh
#!/bin/bash
/usr/local/apache/bin/httpd && sleep 5d
[root@daa4b5196b67 ~]# cd /
[root@daa4b5196b67 /]# chmod +x entrypoint.sh
[root@daa4b5196b67 /]# ./entrypoint.sh
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
//制作镜像
[root@localhost ~]# docker commit -a "web" -c 'CMD ["/entrypoint.sh"]' -p httpd knightsl/httpd:v0.1
sha256:88730628b14b61d029da00c850af8a00e90a7025fef9fabfafc2659b8d5c4b7d
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
knightsl/httpd v0.1 88730628b14b 26 seconds ago 745MB
httpd latest dabbfbe0c57b 7 months ago 144MB
centos latest 5d0da3dc9764 10 months ago 231MB
[root@localhost ~]# docker run -d --name yu -p 80:80 knightsl/httpd:v0.1
1b7b6e74ab01b43c176ee3d9668490cb078aa46ab9109bcd14f7f659376a8bc0
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1b7b6e74ab01 knightsl/httpd:v0.1 "/entrypoint.sh" 6 seconds ago Up 5 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp yu
daa4b5196b67 centos "/bin/bash" 31 minutes ago Up 31 minutes httpd
//上传镜像
[root@localhost ~]# docker login docker.io
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: knightsl
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 knightsl/httpd:v0.1
The push refers to repository [docker.io/knightsl/httpd]
28296efdd03f: Pushed
74ddd0ec08fa: Mounted from library/centos
v0.1: digest: sha256:33bc0f5583e2728946733cdc3d7cba20cebad318c50fad920c943b671869b918 size: 742
[root@localhost ~]# docker pull guguniao/httpd:v0.1
v0.1: Pulling from guguniao/httpd
a1d0c7532777: Pull complete
24f59b1ddf5a: Pull complete
Digest: sha256:13c91a081cdd4a6eacfb1c90ee98b93c380635ec2d789a6eab77adde1d2adc87
Status: Downloaded newer image for guguniao/httpd:v0.1
docker.io/guguniao/httpd:v0.1
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
guguniao/httpd v0.1 b79da2045172 About an hour ago 671MB
[root@localhost ~]# docker run -d --name web1 -p 80:80 guguniao/httpd:v0.1
66dfc485b38abd947746a9db17c8cefb9f731ea4ee8609786fea39ff0d28bbc7
[root@localhost ~]# docker exec -it web1 /bin/bash
[root@66dfc485b38a /]# apachectl