1. 拉取镜像并启动容器
//拉取centos镜像
[root@localhost ~]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
a1d0c7532777: Pull complete
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest
//基于centos镜像启动容器
[root@localhost ~]# docker run -it --name pg1 centos /bin/bash
[root@0f13b7bbdd54 /]#
2.安装apr apr-utils httpd
[root@0f13b7bbdd54 /]# wget http://mirrors.aliyun.com/apache/apr/apr-1.7.0.tar.gz
--2022-08-10 15:17:29-- http://mirrors.aliyun.com/apache/apr/apr-1.7.0.tar.gz
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 119.96.138.217, 119.96.138.211, 58.49.248.229, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|119.96.138.217|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1093896 (1.0M) [application/octet-stream]
Saving to: ‘apr-1.7.0.tar.gz’
apr-1.7.0.tar.gz 100%[===================>] 1.04M 6.73MB/s in 0.2s
2022-08-10 15:17:30 (6.73 MB/s) - ‘apr-1.7.0.tar.gz’ saved [1093896/1093896]
[root@0f13b7bbdd54 /]#
[root@0f13b7bbdd54 /]# tar -xf apr-1.7.0.tar.gz -C /usr/local/src/
[root@0f13b7bbdd54 /]# cd /usr/local/src/apr-1.7.0/
[root@0f13b7bbdd54 apr-1.7.0]# vi configure
$RM "$cfgfile" //注释或删除此行
[root@0f13b7bbdd54 apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@0f13b7bbdd54 apr-1.7.0]# make && make install
[root@0f13b7bbdd54 apr-1.7.0]# cd
[root@0f13b7bbdd54 ~]# wget https://mirrors.aliyun.com/apache/apr/apr-util-1.6.1.tar.gz
--2022-08-10 15:21:52-- https://mirrors.aliyun.com/apache/apr/apr-util-1.6.1.tar.gz
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 119.96.138.215, 119.96.138.210, 58.49.248.229, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|119.96.138.215|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 554301 (541K) [application/octet-stream]
Saving to: ‘apr-util-1.6.1.tar.gz’
apr-util-1.6.1.tar. 100%[===================>] 541.31K --.-KB/s in 0.1s
2022-08-10 15:21:53 (4.34 MB/s) - ‘apr-util-1.6.1.tar.gz’ saved [554301/554301]
[root@0f13b7bbdd54 ~]# tar -xf apr-util-1.6.1.tar.gz -C /usr/local/src/
[root@0f13b7bbdd54 ~]# cd /usr/local/src/apr-util-1.6.1/
[root@0f13b7bbdd54 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
[root@0f13b7bbdd54 apr-util-1.6.1]# make && make install
[root@0f13b7bbdd54 apr-util-1.6.1]# cd
[root@0f13b7bbdd54 ~]# wget https://mirrors.aliyun.com/apache/httpd/httpd-2.4.54.tar.gz
--2022-08-10 15:23:47-- https://mirrors.aliyun.com/apache/httpd/httpd-2.4.54.tar.gz
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 119.96.138.215, 58.49.248.226, 58.49.248.231, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|119.96.138.215|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9743277 (9.3M) [application/octet-stream]
Saving to: ‘httpd-2.4.54.tar.gz’
httpd-2.4.54.tar.gz 100%[===================>] 9.29M 4.55MB/s in 2.0s
2022-08-10 15:23:50 (4.55 MB/s) - ‘httpd-2.4.54.tar.gz’ saved [9743277/9743277]
[root@0f13b7bbdd54 ~]# tar -xf httpd-2.4.54.tar.gz -C /usr/local/src/
[root@0f13b7bbdd54 ~]# cd /usr/local/src/httpd-2.4.54/
[root@0f13b7bbdd54 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@0f13b7bbdd54 httpd-2.4.54]# make && make install
3.配置apache并验证服务
//配置环境变量
[root@0f13b7bbdd54 httpd-2.4.54]# cd
[root@0f13b7bbdd54 ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/apache.sh
[root@0f13b7bbdd54 ~]# source /etc/profile.d/apache.sh
//映射头文件
[root@0f13b7bbdd54 ~]# ln -s /usr/local/apache/include/ /usr/include/apache
//去除提示信息
[root@0f13b7bbdd54 ~]# vi /usr/local/apache/conf/httpd.conf
ServerName www.example.com:80 //将此行取消注释
//启动服务查看状态
[root@0f13b7bbdd54 ~]# httpd
[root@0f13b7bbdd54 ~]# 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:*
[root@0f13b7bbdd54 ~]#
4.制作镜像
//另外连接一个终端进行制作
[root@localhost ~]# docker commit -p -c 'CMD ["/usr/local/apache/bin/httpd","-D","FOREGROUND"]' pg1 0f13b7bbdd54/httpd:v0.1
sha256:eeed0a550ead8bcfa92b760f1869df17c004198408c6ec139d14b2c715c0d810
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
0f13b7bbdd54/httpd v0.1 eeed0a550ead 10 seconds ago 729MB
centos latest 5d0da3dc9764 10 months ago 231MB
[root@localhost ~]#
5. 启动容器
//使用镜像启动容器
[root@localhost ~]# docker run -d --name web -p 80:80 -v /root/html/:/usr/local/apache/htdocs 0f13b7bbdd54/httpd:v0.1
a29e6aae48e20d640c8c6ded73d64d762ab85112db482e2e823ca815640e265f
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a29e6aae48e2 0f13b7bbdd54/httpd:v0.1 "/usr/local/apache/b…" 5 seconds ago Up 4 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp web
0f13b7bbdd54 centos "/bin/bash" 25 minutes ago Up 25 minutes pg1
//测试一下
[root@localhost ~]# echo "paul george!" > html/index.html
[root@localhost ~]# curl 127.0.0.1
paul george!
[root@localhost ~]#
6. 导入源码
[root@localhost ~]# rm -rf html/index.html
[root@localhost ~]# ls html/
README.md css fonts member-list.html
admin-add.html echarts1.html images member-password.html
admin-cate.html echarts2.html index.html order-add.html
admin-edit.html echarts3.html js order-list.html
admin-list.html echarts4.html lib role-add.html
admin-role.html echarts5.html login.html unicode.html
admin-rule.html echarts6.html member-add.html user.json
cate.html echarts7.html member-del.html welcome.html
city.html echarts8.html member-edit.html