使用存储卷部署apache
传输软件包
[root@docker src]# docker run -itd --name apache --hostname apache centos /bin/bash
12efa775c2d8655bfc5611995b43aef34afe5c6c9bc86d41ce6ed0b523e96c48
[root@docker src]# docker cp apr-1.7.0.tar.gz apache:/usr/src
[root@docker src]# docker cp apr-util-1.6.1.tar.gz apache:/usr/src
[root@docker src]# docker cp httpd-2.4.51.tar.gz apache:/usr/src
//解压
[root@docker src]# docker exec -it apache /bin/bash
[root@apache src]# tar xf apr-1.7.0.tar.gz
[root@apache src]# tar xf apr-util-1.6.1.tar.gz
[root@apache src]# tar xf httpd-2.4.51.tar.gz
[root@apache src]# ls
apr-1.7.0 debug
apr-1.7.0.tar.gz httpd-2.4.51
apr-util-1.6.1 httpd-2.4.51.tar.gz
apr-util-1.6.1.tar.gz kernels
下载依赖包
[root@apache ~]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make
创建用户
[root@apache ~]# useradd -r -M -s /nologin apache
编译安装
//进入apr-1.7.0的configure删除这一行
[root@apache ~]# vim /usr/src/apr-1.7.0/configure
$RM "$cfgfile"
//编译apr
[root@apache apr-1.7.0]# ./configure --prefix=/usr/local/apr && make && make install
//编译apr-uitl
[root@apache apr-1.7.0]# cd ../apr-util-1.6.1
[root@apache apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/ && make && make install
//编译httpd
[root@apache httpd-2.4.51]# ./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 && make && make install
//查看ip访问
[root@apache httpd-2.4.51]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
61: eth0@if62: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:c0:a8:42:01 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 192.168.66.1/24 brd 192.168.66.255 scope global eth0
valid_lft forever preferred_lft forever
[root@docker src]# curl 192.168.66.1
<html><body><h1>It works!</h1></body></html>
做成镜像
//写脚本
[root@apache /]# cp -a /usr/local/apache/bin/apachectl /etc/init.d/apache
[root@apache /]# vim start.sh
#! /bin/bash
/etc/init.d/apache start
/bin/bash
[root@docker ~]# docker commit -p -c 'CMD ["/bin/bash","/start.sh"]' apache linlusama/centos-apache:v1
sha256:45b67ad10320518b0d532452e7cd526e98320a321ac2f8de2e92dfe4f331d98c
存储卷
[root@docker ~]# cd /var/www/html/
[root@docker html]# ls
index.html
[root@docker html]# cat index.html
hello world
[root@docker ~]# docker run -it --name apache -p 80:80 -v /var/www/html:/usr/local/apache/htdocs:ro --hostname apache linlusama/centos-apache:v1
[root@apache /]# ls
bin home lost+found opt run start.sh usr
dev lib media proc sbin sys var
etc lib64 mnt root srv tmp
[root@apache /]# cd /usr/local/apache/htdocs/
[root@apache htdocs]# ls
index.html
[root@apache htdocs]# cat index.html
hello world
配置网页
[root@docker html]# ls
index.html js记忆翻牌匹配小游戏代码.zip
[root@docker html]# unzip js记忆翻牌匹配小游戏代码.zip
访问