源码部署apache服务
拉取镜像
[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 run -it --name httpd --network bridge -v /usr/src/:/usr/src -v /usr/local/:/usr/local centos:8
上传源码包
[root@localhost ~]# ls /usr/src/
apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz debug httpd-2.4.48.tar.gz kernels
[root@bb9283a9d50b /]# ls /usr/src/
apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz debug httpd-2.4.48.tar.gz kernels
部署
[root@localhost ~]# cd /usr/src/
[root@localhost src]# tar xf apr-1.7.0.tar.gz
[root@localhost src]# tar xf apr-util-1.6.1.tar.gz
[root@localhost src]# tar xf httpd-2.4.48.tar.gz
[root@bb9283a9d50b /]# ls /usr/src/
apr-1.7.0 apr-1.7.0.tar.gz apr-util-1.6.1 apr-util-1.6.1.tar.gz debug httpd-2.4.48 httpd-2.4.48.tar.gz kernels
//安装开发工具包
[root@bb9283a9d50b /]# yum -y groups mark install 'Development Tools'
Failed to set locale, defaulting to C.UTF-8
CentOS Linux 8 - AppStream 2.1 MB/s | 8.2 MB 00:03
CentOS Linux 8 - BaseOS 2.6 MB/s | 3.5 MB 00:01
CentOS Linux 8 - Extras 11 kB/s | 10 kB 00:00
Dependencies resolved.
===========================================================================================================================================
Package Architecture Version Repository Size
===========================================================================================================================================
Installing Groups:
Development Tools
Transaction Summary
===========================================================================================================================================
Complete!
//安装依赖包
[root@bb9283a9d50b /]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make
//源码安装apr
[root@bb9283a9d50b /]# cd /usr/src/
[root@bb9283a9d50b src]# cd apr-1.7.0
[root@bb9283a9d50b apr-1.7.0]# vim configure
cfgfile=${ofile}T
trap "$RM \"$cfgfile\"; exit 1" 1 2 15
$RM "$cfgfile" //删掉此行
[root@bb9283a9d50b apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@bb9283a9d50b apr-1.7.0]# make && make install
//编译安装apr-util
[root@bb9283a9d50b apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && make && make install
//编译安装httpd
[root@d21b76a5fced httpd-2.4.48]# ./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@bb9283a9d50b src]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@bb9283a9d50b src]# source /etc/profile.d/httpd.sh
[root@bb9283a9d50b src]# ln -s /usr/local/apache/include/ /usr/include/httpd
[root@bb9283a9d50b src]# vim /etc/man_db.conf
[root@bb9283a9d50b src]# cat /etc/man_db.conf
#
MANDATORY_MANPATH /usr/man
MANDATORY_MANPATH /usr/share/man
MANDATORY_MANPATH /usr/local/share/man
MANDATORY_MANPATH /usr/local/apache/man
//去掉注释
[root@bb9283a9d50b httpd-2.4.48]# vim /usr/local/apache/conf/httpd.conf
ServerName www.example.com:80
//启动apache
[root@bb9283a9d50b httpd-2.4.48]# apachectl start
[root@bb9283a9d50b httpd-2.4.48]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
打包成镜像
安装nfs
打开另外一台虚拟机
[root@docker ~]# yum -y install nfs-utils
[root@localhost ~]# mkdir /nfs
[root@localhost ~]# vim /etc/exports
[root@localhost ~]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
[root@localhost ~]# systemctl start nfs-utils.service
docker主机上安装nfs
评论区