44293a537755 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-rpm=prefork
[root@44293a537755 httpd-2.4.54]# make && make install
配置环境变量
/配置环境变量
[root@44293a537755 ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/apache.sh
[root@44293a537755 ~]# source /etc/profile.d/apache.sh
//创建头文件
[root@44293a537755 ~]# ln -s /usr/local/apache/include/ /usr/include/apache
//取消启动警告
[root@6cd57ac5f6e7 ~]# vim /usr/local/apache/conf/httpd.conf
ServerName www.example.com:80 //取消注释
//启动apache服务
[root@6cd57ac5f6e7 ~]# apachectl start
[root@6cd57ac5f6e7 ~]# 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@6cd57ac5f6e7 ~]# curl 127.0.0.1
<html><body><h1>It works!</h1></body></html>
制作镜像
在开启一个终端进行操作
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6cd57ac5f6e7 centos:8 "/bin/bash" 13 hours ago Up 12 hours httpd
//-p参数是让正在运作中的容器先暂停等制作完镜像。-c后面跟上的命令是让该镜像作为容器启动时把httpd服务也启用
[root@localhost ~]# docker commit -p -c 'CMD ["/usr/local/apache/bin/httpd","-D","FOREGROUND"]' 6cd57ac5f6e7 xinruizhong/httpd:v1.1
sha256:65836c5507843e93afef9baf8e5dbf8c61b7166a560ff28e8f2fa9a94d4a7fbe
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
xinruizhong/httpd v1.1 65836c550784 14 seconds ago 789MB
centos 8 5d0da3dc9764 10 months ago 231MB
//首次登录需要提供用户名和密码
[root@localhost ~]# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: xinruizhong
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
[root@localhost ~]# docker push xinruizhong/httpd:v1.1 //上传镜像
The push refers to repository [docker.io/xinruizhong/httpd]
a3705dc88dcd: Pushed
74ddd0ec08fa: Layer already exists
v1.1: digest: sha256:a5b133a68e0bb18860b7c9361e32ae93943f95c188bf0d126d1995d4f16d02b7 size: 742
测试镜像,并部署网页
//使用创建的镜像创建容器,并挂载存储卷
[root@localhost ~]# docker run -d --name web --restart always -p 80:80 -v /root/httpd_html:/usr/local/apache/htdocs xinruizhong/httpd:v1.1
13a1d5674f411590169702d564522f95f6371e1c702749fc76e17dfa20a2860e
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
13a1d5674f41 xinruizhong/httpd:v1.1 "/usr/local/apache/b…" 4 minutes ago Up 4 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp web
6cd57ac5f6e7 centos:8 "/bin/bash" 14 hours ago Up 13 hours httpd
//导入下载的压缩包,配置网站
[root@localhost ~]# cd /root/httpd_html/
[root@localhost httpd_html]# ls
youxi.zip
[root@localhost httpd_html]# unzip youxi.zip
[root@localhost httpd_html]# rm -rf youxi.zip
[root@localhost httpd_html]# ls
Web.config from.gif index.html
浏览器访问