使用基于容器的方式编译安装apache做成镜像
使用基于容器的方式编译安装apache做成镜像,要能够使用此镜像创建一个能访问web网站的容器
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd latest c30a46771695 6 days ago 144MB
busybox latest 1a80408de790 12 days ago 1.24MB
centos latest 5d0da3dc9764 7 months ago 231MB
[root@localhost ~]# docker run --name h1 -it centos
[root@c6051d74b828 /]#
[root@c6051d74b828 /]# cd /etc/yum.repos.d/
[root@c6051d74b828 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@c6051d74b828 yum.repos.d]# rm -rf *
[root@c6051d74b828 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 13342 0 --:--:-- --:--:-- --:--:-- 13342
[root@c6051d74b828 yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@c6051d74b828 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
CentOS-8.5.2111 - Base - mirrors.aliyun.com 2.8 MB/s | 4.6 MB 00:01
CentOS-8.5.2111 - Extras - mirrors.aliyun.com 68 kB/s | 10 kB 00:00
CentOS-8.5.2111 - AppStream - mirrors.aliyun.com 2.3 MB/s | 8.4 MB 00:03
epel-release-latest-8.noarch.rpm 210 kB/s | 23 kB 00:00
Dependencies resolved.
=================================================================================================
Package Architecture Version Repository Size
=================================================================================================
Installing:
epel-release noarch 8-15.el8 @commandline 23 k
Transaction Summary
=================================================================================================
Install 1 Package
Total size: 23 k
Installed size: 32 k
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : epel-release-8-15.el8.noarch 1/1
Running scriptlet: epel-release-8-15.el8.noarch 1/1
Verifying : epel-release-8-15.el8.noarch 1/1
Installed:
epel-release-8-15.el8.noarch
Complete!
[root@c6051d74b828 yum.repos.d]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@c6051d74b828 yum.repos.d]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
[root@c6051d74b828 yum.repos.d]# ls
CentOS-Base.repo epel-modular.repo epel-testing-modular.repo epel-testing.repo epel.repo
[root@c6051d74b828]# yum group mark install "Development Tools" //安装开发工具包
上次元数据过期检查:21:12:37 前,执行于 2022年04月16日 星期六 06时57分08秒。
依赖关系解决。
=======================================================================================
软件包 架构 版本 仓库
=======================================================================================
安装组:
Development Tools
事务概要
=======================================================================================
确定吗?[y/N]: y
完毕!
[root@c6051d74b828]# useradd -r -M -s /sbin/nologin apache 创建Apache用户
[root@c6051d74b828]# id apache
uid=48(apache) gid=48(apache) 组=48(apache)
[root@c6051d74b828]# grep apache /etc/group
apache:x:48:
[root@c6051d74b828]# yum -y install openssl-devel pcre-devel expat-devel libtool //安装依赖包
上次元数据过期检查:21:20:27 前,执行于 2022年04月16日 星期六 06时57分08秒。
软件包 libtool-2.4.6-25.el8.x86_64 已安装。
依赖关系解决。
======================================================================================
软件包 架构 版本 仓库 大小
======================================================================================
安装:
expat-devel x86_64 2.2.5-8.el8 baseos 57 k
openssl-devel x86_64 1:1.1.1k-6.el8 baseos 2.3 M
pcre-devel x86_64 8.42-6.el8 baseos 551 k
//安装之后用到的命令工具
[root@c6051d74b828]# dnf -y install wget
[root@c6051d74b828]# dnf -y install gcc gcc-c++
[root@c6051d74b828]# dnf -y install vim
[root@c6051d74b828]# dnf -y install make
//使用wget命令下载apr-1.7.0,apr-util-1.6.1,httpd-2.4.53安装包
[root@c6051d74b828]# wget https://downloads.apache.org/apr/apr-1.7.0.tar.gz
[root@c6051d74b828]# wget https://downloads.apache.org/httpd/httpd-2.4.53.tar.gz
[root@c6051d74b828]# wget https://downloads.apache.org/httpd/httpd-2.4.53.tar.gz
[root@c6051d74b828]# ls //可以看到已经下载完成
anaconda-ks.cfg apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.53.tar.gz
[root@c6051d74b828]# tar xf apr-1.7.0.tar.gz
[root@c6051d74b828]# tar xf apr-util-1.6.1.tar.gz
[root@c6051d74b828]# tar xf httpd-2.4.53.tar.gz
[root@c6051d74b828]# ls
anaconda-ks.cfg apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.53.tar.gz
apr-1.7.0 apr-util-1.6.1 httpd-2.4.53
[root@c6051d74b828]# cd apr-1.7.0
[root@c6051d74b828 apr-1.7.0]#
[root@c6051d74b828 apr-1.7.0]# ls
apr-config.in build.conf dso libapr.rc NOTICE support
apr.dep buildconf emacs-mode LICENSE NWGNUmakefile tables
apr.dsp build-outputs.mk encoding locks passwd test
apr.dsw CHANGES file_io Makefile.in poll threadproc
apr.mak CMakeLists.txt helpers Makefile.win random time
apr.pc.in config.layout include memory README tools
apr.spec configure libapr.dep misc README.cmake user
atomic configure.in libapr.dsp mmap shmem
build docs libapr.mak network_io strings
[root@c6051d74b828 apr-1.7.0]# vim configure
cfgfile="${ofile}T"
trap "$RM \"$cfgfile\"; exit 1" 1 2 15
#$RM "$cfgfile" //将此行注释,或删除
[root@c6051d74b828 apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@c6051d74b828 apr-1.7.0]# make //编译
[root@c6051d74b828 apr-1.7.0]# make install //安装
[root@c6051d74b828 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr //编译子包时需要告诉主包位置
[root@c6051d74b828 apr-util-1.6.1]# make //编译
[root@c6051d74b828 apr-util-1.6.1]# make install
[root@c6051d74b828 apr-util-1.6.1]# cd ../httpd-2.4.53
[root@c6051d74b828 httpd-2.4.53]#
[root@c6051d74b828 httpd-2.4.53]# pwd
/root/httpd-2.4.53
[root@c6051d74b828 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@c6051d74b828 httpd-2.4.53]# make
[root@c6051d74b828 httpd-2.4.53]# make install
[root@c6051d74b828 httpd-2.4.53]# cd
[root@c6051d74b828]#
[root@c6051d74b828]#
[root@c6051d74b828]# ls
anaconda-ks.cfg apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.53.tar.gz
apr-1.7.0 apr-util-1.6.1 httpd-2.4.53
[root@c6051d74b828]# ls /usr/local/
apache apr-util etc include lib64 sbin src
apr bin games lib libexec share
[root@c6051d74b828]# cd /usr/local/apache/
[root@c6051d74b828 apache]# ls
bin build cgi-bin conf error htdocs icons include logs man manual
设置环境变量
[root@c6051d74b828]# echo 'export PATH=/usr/loacl/apache/bin:$PATH'>/etc/profile.d/apache.sh
[root@c6051d74b828]#
[root@c6051d74b828]# source /etc/profile.d/apache.sh
[root@c6051d74b828]# which httpd //查看httpd命令
/usr/local/apache/bin/httpd
[root@c6051d74b828]# which apachectl //查看apachectl命令
/usr/local/apache/bin/apachectl
[root@c6051d74b828 ~]# cd /usr/lib/systemd/system
[root@c6051d74b828 system]# vi httpd.service
[root@c6051d74b828 system]# cat httpd.service
[Unit]
Description=httpd server daemon
After=network.target sshd-keygen.target
[Service]
Type=forking
ExecStart=/usr/local/apache/bin/apachectl start
Execstop=/usr/local/apache/bin/apachectl stop
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
[root@c6051d74b828 system]# systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@localhost ~]# docker commit -a'stares<a1@bb>' -c 'CMD["/bin/httpd","-f","-h","/data"]' -p
修改
//配置国内阿里云的源
[root@localhost yum.repos.d]# rm -rf *
[root@localhost yum.repos.d]# ls
[root@localhost 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 21324 0 --:--:-- --:--:-- --:--:-- 21324
[root@localhost yum.repos.d]# ls
CentOS-Base.repo
[root@localhost yum.repos.d]# dnf -y install vim wget
CentOS-8.5.2111 - Base - mirrors.aliyun.com 4.0 MB/s | 4.6 MB 00:01
CentOS-8.5.2111 - Extras - mirrors.aliyun.com 139 kB/s | 10 kB 00:00
CentOS-8.5.2111 - AppStream - mirrors.aliyun.com 4.2 MB/s | 8.4 MB 00:02
软件包 vim-enhanced-2:8.0.1763-16.el8_5.12.x86_64 已安装。
依赖关系解决。
======================================================================================
软件包 架构 版本 仓库 大小
======================================================================================
安装:
wget x86_64 1.19.5-10.el8 AppStream 734 k
安装依赖关系:
libmetalink x86_64 0.1.3-7.el8 base 32 k
事务概要
======================================================================================
安装 2 软件包
总下载:766 k
安装大小:2.8 M
下载软件包:
(1/2): libmetalink-0.1.3-7.el8.x86_64.rpm 791 kB/s | 32 kB 00:00
(2/2): wget-1.19.5-10.el8.x86_64.rpm 2.3 MB/s | 734 kB 00:00
--------------------------------------------------------------------------------------
总计 2.4 MB/s | 766 kB 00:00
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
准备中 : 1/1
安装 : libmetalink-0.1.3-7.el8.x86_64 1/2
安装 : wget-1.19.5-10.el8.x86_64 2/2
运行脚本: wget-1.19.5-10.el8.x86_64 2/2
验证 : libmetalink-0.1.3-7.el8.x86_64 1/2
验证 : wget-1.19.5-10.el8.x86_64 2/2
已安装:
libmetalink-0.1.3-7.el8.x86_64 wget-1.19.5-10.el8.x86_64
完毕!
[root@localhost yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@localhost yum.repos.d]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
CentOS-8.5.2111 - Base - mirrors.aliyun.com 82 kB/s | 3.9 kB 00:00
CentOS-8.5.2111 - Extras - mirrors.aliyun.com 39 kB/s | 1.5 kB 00:00
CentOS-8.5.2111 - AppStream - mirrors.aliyun.com 112 kB/s | 4.3 kB 00:00
epel-release-latest-8.noarch.rpm 289 kB/s | 23 kB 00:00
依赖关系解决。
======================================================================================
软件包 架构 版本 仓库 大小
======================================================================================
安装:
epel-release noarch 8-15.el8 @commandline 23 k
事务概要
======================================================================================
安装 1 软件包
总计:23 k
安装大小:32 k
下载软件包:
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
准备中 : 1/1
安装 : epel-release-8-15.el8.noarch 1/1
运行脚本: epel-release-8-15.el8.noarch 1/1
验证 : epel-release-8-15.el8.noarch 1/1
已安装:
epel-release-8-15.el8.noarch
完毕!
[root@localhost yum.repos.d]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@localhost yum.repos.d]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
[root@localhost yum.repos.d]# ls
CentOS-Base.repo epel.repo epel-testing.repo
epel-modular.repo epel-testing-modular.repo
//下载阿里云里面的docker-ce.repo
[root@localhost yum.repos.d]# wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
--2022-04-24 07:27:40-- https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 111.48.71.115, 111.48.71.116, 111.48.71.117, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|111.48.71.115|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2081 (2.0K) [application/octet-stream]
正在保存至: “docker-ce.repo”
docker-ce.repo 100%[=======================>] 2.03K --.-KB/s 用时 0s
2022-04-24 07:27:40 (92.4 MB/s) - 已保存 “docker-ce.repo” [2081/2081])
[root@localhost yum.repos.d]# ls //可以看到已经下载完成
CentOS-Base.repo epel-modular.repo epel-testing-modular.repo
docker-ce.repo epel.repo epel-testing.repo
[root@localhost yum.repos.d]# cd
[root@localhost ~]# dnf makecache //建立缓存
CentOS-8.5.2111 - Base - mirrors.aliyun.com 75 kB/s | 3.9 kB 00:00
CentOS-8.5.2111 - Extras - mirrors.aliyun.com 63 kB/s | 1.5 kB 00:00
CentOS-8.5.2111 - AppStream - mirrors.aliyun.com 118 kB/s | 4.3 kB 00:00
Docker CE Stable - x86_64 117 kB/s | 23 kB 00:00
Extra Packages for Enterprise Linux 8 - x86_64 4.1 MB/s | 11 MB 00:02
Extra Packages for Enterprise Linux Modular 8 - x86_6 2.6 MB/s | 1.0 MB 00:00
元数据缓存已建立。
[root@localhost ~]# dnf list all | grep docker //过滤docker
containerd.io.x86_64 1.5.11-3.1.el8 docker-ce-stable
docker-ce.x86_64 3:20.10.14-3.el8 docker-ce-stable
docker-ce-cli.x86_64 1:20.10.14-3.el8 docker-ce-stable
docker-ce-rootless-extras.x86_64 20.10.14-3.el8 docker-ce-stable
docker-compose-plugin.x86_64 2.3.3-3.el8 docker-ce-stable
docker-scan-plugin.x86_64 0.17.0-3.el8 docker-ce-stable
pcp-pmda-docker.x86_64 5.3.1-5.el8 AppStream
podman-docker.noarch 3.3.1-9.module_el8.5.0+988+b1f0b741 AppStream
python-docker-tests.noarch 5.0.0-2.el8 epel
python2-dockerpty.noarch 0.4.1-18.el8 epel
python3-docker.noarch 5.0.0-2.el8 epel
python3-dockerpty.noarch 0.4.1-18.el8 epel
standard-test-roles-inventory-docker.noarch 4.10-1.el8 epel
[root@localhost ~]# dnf -y install docker-ce //安装docker最新版本
//设置开机自启
[root@localhost ~]# systemctl enable --now docker
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.
[root@localhost ~]# systemctl status docker //查看状态
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: di>
Active: active (running) since Sun 2022-04-24 07:39:32 EDT; 8s ago
Docs: https://docs.docker.com
Main PID: 4890 (dockerd)
Tasks: 8
Memory: 29.2M
CGroup: /system.slice/docker.service
└─4890 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.s>
4月 24 07:39:31 localhost.localdomain dockerd[4890]: time="2022-04-24T07:39:31.193612>
4月 24 07:39:31 localhost.localdomain dockerd[4890]: time="2022-04-24T07:39:31.193632>
4月 24 07:39:31 localhost.localdomain dockerd[4890]: time="2022-04-24T07:39:31.193761>
4月 24 07:39:32 localhost.localdomain dockerd[4890]: time="2022-04-24T07:39:32.135829>
[root@localhost ~]# ls /etc/docker/ //这时可以看到自动生成一个docker目录
key.json
[root@localhost ~]# vi daemon.json //复制粘贴配置一个文件
[root@localhost ~]# cat daemon.json
{
"registry-mirrors": ["https://7fh8zy6l.mirror.aliyuncs.com"]
}
[root@localhost ~]# systemctl daemon-reload //重启docaker服务
[root@localhost ~]# systemctl restart docker
[root@localhost ~]# docker info //查看docker状态
Client:
Context: default
Debug Mode: false
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Docker Buildx (Docker Inc., v0.8.1-docker)
scan: Docker Scan (Docker Inc., v0.17.0)
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 20.10.14
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc io.containerd.runc.v2 io.containerd.runtime.v1.linux
Default Runtime: runc
Init Binary: docker-init
containerd version: 3df54a852345ae127d1fa3092b95168e4a88e2f8
runc version: v1.0.3-0-gf46b6ba
init version: de40ad0
Security Options:
seccomp
Profile: default
Kernel Version: 4.18.0-365.el8.x86_64
Operating System: CentOS Stream 8
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.744GiB
Name: localhost.localdomain
ID: PHFK:HHSO:OII6:RR7X:GJPM:GSKG:DWRJ:O2RZ:ZPOT:SZYM:UBVL:EGHL
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Registry Mirrors: //看到这个网址说明docker加速器服务配置成功
https://7fh8zy6l.mirror.aliyuncs.com/
Live Restore Enabled: false
[root@localhost ~]# docker pull centos:8 //拉取镜像
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd latest c30a46771695 6 days ago 144MB
busybox latest 1a80408de790 12 days ago 1.24MB
centos latest 5d0da3dc9764 7 months ago 231MB
[root@localhost ~]# docker run -it --name httpd centos:8 /bin/bash
[root@acbe1d502bf5 /]#
[root@acbe1d502bf5 /]# cd /etc/yum.repos.d/
[root@acbe1d502bf5 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@acbe1d502bf5 yum.repos.d]# rm -rf *
[root@acbe1d502bf5 yum.repos.d]# ls
[root@acbe1d502bf5 yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@acbe1d502bf5 yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@acbe1d502bf5 yum.repos.d]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@acbe1d502bf5 yum.repos.d]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@acbe1d502bf5 yum.repos.d]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
[root@acbe1d502bf5 yum.repos.d]# yum clean all
[root@acbe1d502bf5 yum.repos.d]# yum makecache
//下载apache安装包
[root@localhost ~]# wget https://downloads.apache.org/apr/apr-1.7.0.tar.gz
[root@localhost ~]# wget https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz
[root@localhost ~]# wget https://downloads.apache.org/httpd/httpd-2.4.53.tar.gz
//将安装包上传到httpd容器上
[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/
[root@localhost ~]# docker exce -it httpd /bin/bash
[root@acbe1d502bf5 ~]# ls /usr/src/
apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz debug httpd-2.4.53.tar.gz kernels
//准备apache的基础环境
[root@acbe1d502bf5 ~]# yum groups mark install 'Development Tools' -y
[root@acbe1d502bf5 ~]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make
[root@acbe1d502bf5 ~]# useradd -r -M -s /sbin/nologin apache
//编译安装httpd,此操作和之前编译httpd一样
[root@acbe1d502bf5 ~]# cd /usr/src/
[root@acbe1d502bf5 src]# tar -xf apr-1.7.0.tar.gz
[root@acbe1d502bf5 src]# cd apr-1.7.0
[root@acbe1d502bf5 apr-1.7.0]# vi configure
cfgfile="${ofile}T"
trap "$RM \"$cfgfile\"; exit 1" 1 2 15
$RM "$cfgfile" //将此行加上注释,或者删除此行
[root@acbe1d502bf5 apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@acbe1d502bf5 apr-1.7.0]# make
[root@acbe1d502bf5 apr-1.7.0]# make install
[root@acbe1d502bf5 apr-1.7.0]# cd ..
[root@acbe1d502bf5 src]# tar -xf apr-util-1.6.1.tar.gz
[root@acbe1d502bf5 src]# cd apr-util-1.6.1
[root@acbe1d502bf5 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
[root@acbe1d502bf5 apr-util-1.6.1]# make
[root@acbe1d502bf5 apr-util-1.6.1]# make install
[root@acbe1d502bf5 apr-util-1.6.1]# cd ..
[root@acbe1d502bf5 src]# tar -xf httpd-2.4.53.tar.gz
[root@acbe1d502bf5 src]# cd httpd-2.4.53
[root@acbe1d502bf5 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@acbe1d502bf5 httpd-2.4.53]# make
[root@acbe1d502bf5 httpd-2.4.53]# make install
//设置环境变量 做映射关系 头文件 man文件
[root@acbe1d502bf5 httpd-2.4.53]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/apache.sh
[root@acbe1d502bf5 httpd-2.4.53]# source /etc/profile.d/apache.sh
[root@acbe1d502bf5 httpd-2.4.53]# yum -y install which
[root@acbe1d502bf5 httpd-2.4.53]# which httpd
/usr/local/apache/bin/httpd
[root@acbe1d502bf5 httpd-2.4.53]# ln -s /usr/local/apache/include/ /usr/include/apache
[root@lch conf]# vi httpd.conf
#ServerName www.example.com:80 // 此行取消注释
[root@acbe1d502bf5 ~]# apachectl start
[root@acbe1d502bf5 ~]# 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@acbe1d502bf5 ~]# echo "/usr/sbin/httpd -DFOREGROUND" > start.sh
[root@acbe1d502bf5 ~]# chmod a+x start.sh //给启动脚本添加运行权限
//制作镜像
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d1040fce381b centos:8 "/bin/bash" 54 minutes ago Up 50 minutes httpd
[root@localhost ~]# docker commit -p -c 'CMD ["/bin/bash","/start.sh"]' d1040fce381b feigeaq/httpd:v1.0
sha256:95d3c31094384d922ebe113bc4bb48a53156974fa92d380e534aed2385acc417
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
feigeaq/httpd v1.0 95d3c3109438 39 seconds ago 749MB
centos 8 5d0da3dc9764 7 months ago 231MB
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d1040fce381b centos:8 "/bin/bash" 58 minutes ago Up 54 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 feigeaq/httpd:v1.0 /bin/bash
d72748777112a65378dba45888f2460c5d38f3718a620702bd336e88e40553cf
[root@localhost ~]# . /start.sh
[root@localhost ~]# docker exec -it web /bin/bash
[root@d72748777112 /]#
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d72748777112 feigeaq/httpd:v1.0 "/bin/bash" 38 seconds ago Up 37 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp web