[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
caiaoc/mysql v1.0 ba85e9d47f00 2 days ago 3.81GB
caiaoc/nginx v1.0 a985a6973aec 2 days ago 549MB
caiaoc/php v1.0 f5fe6827f02b 2 days ago 1.46GB
busybox latest d23834f29b38 6 days ago 1.24MB
httpd latest ad17c88403e2 2 weeks ago 143MB
nginx latest ea335eea17ab 2 weeks ago 141MB
centos latest 5d0da3dc9764 2 months ago 231MB
//通过centos镜像的基础上搭建httpd服务
[root@docker ~]# docker run -it --name httpd centos /bin/bash
[root@17c934af0f95 /]#
//在本地将包上传到httpd容器中
[root@docker ~]# ls
apr-1.7.0.tar.gz httpd-2.4.48.tar.gz
apr-util-1.6.1.tar.gz pure-css3-lighter.rar
[root@docker ~]# docker cp apr-1.7.0.tar.gz httpd:/usr/src/
[root@docker ~]# docker cp apr-util-1.6.1.tar.gz httpd:/usr/src/
[root@docker ~]# docker cp httpd-2.4.48.tar.gz httpd:/usr/src/
[root@docker ~]#
//安装开发工具包组
[root@17c934af0f95 ~]# yum groups mark install 'Development Tools' -y
//安装依赖包
[root@17c934af0f95 ~]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make
//创建apache服务的用户和组
[root@17c934af0f95 ~]# useradd -r -M -s /sbin/nologin apache
//解压包
[root@17c934af0f95 ~]# cd /usr/src/
[root@17c934af0f95 src]# ls
apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz debug httpd-2.4.48.tar.gz kernels
[root@17c934af0f95 src]# tar xf apr-1.7.0.tar.gz
[root@17c934af0f95 src]# tar xf apr-util-1.6.1.tar.gz
[root@17c934af0f95 src]# tar xf httpd-2.4.48.tar.gz
[root@17c934af0f95 src]# ls
apr-1.7.0 apr-util-1.6.1 debug httpd-2.4.48.tar.gz
apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.48 kernels
[root@17c934af0f95 src]#
//编译安装apr
[root@17c934af0f95 src]# cd apr-1.7.0
[root@17c934af0f95 apr-1.7.0]# vi configure
[root@17c934af0f95 apr-1.7.0]# cat configure
......
cfgfile="${ofile}T"
trap "$RM \"$cfgfile\"; exit 1" 1 2 15
$RM "$cfgfile" //将此行加上注释,或者删除此行
......
[root@17c934af0f95 apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@17c934af0f95 apr-1.7.0]# make && make install
//编译安装apr-util
[root@17c934af0f95 apr-util-1.6.1]# cd ../apr-util-1.6.1
[root@17c934af0f95 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@17c934af0f95 apr-util-1.6.1]# make && make install
//编译安装httpd
[root@17c934af0f95 apr-util-1.6.1]# cd ../httpd-2.4.48
[root@17c934af0f95 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@17c934af0f95 httpd-2.4.48]# make && make install
//安装后配置
[root@17c934af0f95 ~]# ln -s /usr/local/apache/include/ /usr/include/httpd
[root@17c934af0f95 ~]# vi /usr/local/apache/conf/httpd.conf
......
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName www.example.com:80 # 取消配置文件中ServerName前面的注释
......
//启动httpd
[root@17c934af0f95 ~]# /usr/local/apache/bin/httpd
[root@17c934af0f95 ~]# 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@17c934af0f95 ~]#
//编写httpd启动脚本
[root@17c934af0f95 ~]# vi /start.sh
[root@17c934af0f95 ~]# chmod + /start.sh
[root@17c934af0f95 ~]# cat /start.sh
#!/bin/sh
/usr/local/apache/bin/httpd
/bin/bash
[root@17c934af0f95 ~]#
//制作httpd镜像(另起一个终端,httpd容器不能停止)
[root@docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
17c934af0f95 centos "/bin/bash" About an hour ago Up About an hour httpd
[root@docker ~]#
[root@docker ~]# docker commit -p -c 'CMD ["/bin/bash","/start.sh"]' 17c934af0f95 caiaoc/httpd:v1.0
sha256:7340d8864b7ce782e2868e6b56a440d677db047e06518278e8ccb44680627fcb
[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
caiaoc/httpd v1.0 7340d8864b7c 3 seconds ago 712MB
caiaoc/mysql v1.0 ba85e9d47f00 2 days ago 3.81GB
caiaoc/nginx v1.0 a985a6973aec 2 days ago 549MB
caiaoc/php v1.0 f5fe6827f02b 2 days ago 1.46GB
busybox latest d23834f29b38 6 days ago 1.24MB
httpd latest ad17c88403e2 2 weeks ago 143MB
nginx latest ea335eea17ab 2 weeks ago 141MB
centos latest 5d0da3dc9764 2 months ago 231MB
[root@docker ~]#
//首先创建nfs共享存储
[root@nfs ~]# mkdir /nfs
[root@nfs ~]# vi /etc/exports
[root@nfs ~]# cat /etc/exports
/nfs 192.168.200.145(rw)
[root@nfs ~]#
[root@nfs ~]# yum -y install nfs-utils
[root@nfs ~]# systemctl enable --now nfs-server
Created symlink /etc/systemd/system/multi-user.target.wants/nfs-server.service → /usr/lib/systemd/system/nfs-server.service.
[root@nfs ~]# systemctl restart nfs-server
[root@nfs ~]# systemctl disable --now firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@nfs ~]# vi /etc/selinux/config
[root@nfs ~]# setenforce 0
[root@nfs ~]# getenforce 0
Permissive
[root@nfs ~]#
[root@nfs ~]# showmount -e 192.168.200.144
Export list for 192.168.200.144:
/nfs 192.168.200.145
[root@nfs ~]#
//centos8上用的是nobody用户来共享存储(centos7上用的是nfsnobody用户来执行共享存储)
[root@nfs ~]# id nobody
uid=65534(nobody) gid=65534(nobody) 组=65534(nobody)
[root@nfs ~]#
//设置/nfs读写执行
[root@nfs ~]# setfacl -m u:nobody:rwx /nfs
[root@nfs ~]# getfacl /nfs
getfacl: Removing leading '/' from absolute path names
# file: nfs
# owner: root
# group: root
user::rwx
user:nobody:rwx
group::r-x
mask::rwx
other::r-x
[root@nfs ~]#
docker主机配置
//在docker主机上安装nfs
[root@docker ~]# yum -y install nfs-utils
[root@docker ~]# mkdir /storage
[root@docker ~]# mount -t nfs 192.168.200.144:/nfs /storage/
[root@docker ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 1.8G 0 1.8G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 9.1M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/cs-root 64G 8.6G 56G 14% /
/dev/mapper/cs-home 32G 255M 31G 1% /home
/dev/sda1 1014M 195M 820M 20% /boot
tmpfs 371M 0 371M 0% /run/user/0
192.168.200.144:/nfs 62G 2.0G 60G 4% /storage
[root@docker ~]#
//映射httpd的网页目录/usr/local/apache/htdocs到nfs挂载的/storage上
[root@docker ~]# docker run -it --name web -p 80:80 -v /storage:/usr/local/apache/htdocs 7340d8864b7c
[root@c73146535427 /]# 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@c73146535427 /]#
//提供在/storage上网页文件
[root@docker ~]# cd /storage/
[root@docker storage]# ls
[root@docker storage]#
[root@docker storage]# ls
jiaoben1765
[root@docker storage]# cd jiaoben1765/
[root@docker jiaoben1765]# ls
css img index.html js
[root@docker jiaoben1765]#