docker容器源码怎样部署httpd用存储卷部署网站
发表于:2026-11-02 作者:千家信息网编辑
千家信息网最后更新 2026年11月02日,这篇文章将为大家详细讲解有关docker容器源码怎样部署httpd用存储卷部署网站,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。docker容器源码部
千家信息网最后更新 2026年11月02日docker容器源码怎样部署httpd用存储卷部署网站
这篇文章将为大家详细讲解有关docker容器源码怎样部署httpd用存储卷部署网站,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
docker容器源码部署httpd,用存储卷部署网站
创建一个httpd镜像
// 创建一个httpd容器[root@localhost ~]# docker run -tid --name httpd centos2d693e16f4f3734b127cbae90d189c1b4e78619a54ceec912a82d96cf4f1c345[root@localhost ~]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES2d693e16f4f3 centos "/bin/bash" 5 seconds ago Up 4 seconds httpd// 连接上这个容器[root@localhost ~]# docker exec -it 2d693e16f4f3 /bin/bash[root@2d693e16f4f3 /]# // 把源码包放到容器中[root@localhost ~]# docker cp /usr/src/apr-1.7.0.tar.gz 2d693e16f4f3:/usr/src/[root@localhost ~]# docker cp /usr/src/apr-util-1.6.1.tar.gz 2d693e16f4f3:/usr/src/[root@localhost ~]# docker cp /usr/src/httpd-2.4.49.tar.gz 2d693e16f4f3:/usr/src/[root@2d693e16f4f3 /]# ls /usr/src/apr-1.7.0.tar.gz debug kernelsapr-util-1.6.1.tar.gz httpd-2.4.49.tar.gz// 源码安装httpd[root@2d693e16f4f3 /]# useradd -r -M -s /sbin/nologin apache[root@2d693e16f4f3 /]# id apacheuid=998(apache) gid=996(apache) groups=996(apache)[root@2d693e16f4f3 /]# yum groups mark install 'Development Tools' -y[root@2d693e16f4f3 /]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make[root@2d693e16f4f3 /]# cd /usr/src/[root@2d693e16f4f3 src]# tar xf apr-1.7.0.tar.gz -C /usr/local/[root@2d693e16f4f3 src]# tar xf apr-util-1.6.1.tar.gz -C /usr/local/[root@2d693e16f4f3 src]# tar xf httpd-2.4.49.tar.gz -C /usr/local/[root@2d693e16f4f3 src]# cd /usr/local/apr-1.7.0/[root@2d693e16f4f3 apr-1.7.0]# vi configurecfgfile="${ofile}T" trap "$RM \"$cfgfile\"; exit 1" 1 2 15 # $RM "$cfgfile" //将此行加上注释,或者删除此行[root@2d693e16f4f3 apr-1.7.0]# ./configure --prefix=/usr/local/apr[root@2d693e16f4f3 apr-1.7.0]# make && make install[root@2d693e16f4f3 local]# cd apr-util-1.6.1/[root@2d693e16f4f3 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/[root@2d693e16f4f3 apr-util-1.6.1]# make && make install[root@2d693e16f4f3 apr-util-1.6.1]# cd ../httpd-2.4.49/ [root@2d693e16f4f3 httpd-2.4.49]# ./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@2d693e16f4f3 httpd-2.4.49]# make && make install[root@2d693e16f4f3 local]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh[root@2d693e16f4f3 local]# source /etc/profile.d/httpd.sh[root@2d693e16f4f3 local]# ln -s /usr/local/apache/include /usr/include/apache[root@2d693e16f4f3 local]# apachectl start[root@2d693e16f4f3 local]# ss -anltState Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 128 0.0.0.0:80 0.0.0.0:* [root@2d693e16f4f3 local]# cd /[root@2d693e16f4f3 /]# [root@2d693e16f4f3 /]# [root@2d693e16f4f3 /]# vi start.sh#! /bin/sh/usr/local/apache/bin/apachectl start/bin/bash[root@2d693e16f4f3 /]# chmod +x start.sh// 构建镜像[root@localhost ~]# docker commit -p -c 'CMD ["/bin/bash","start.sh"]' 2d693e16f4f3 syblyw0806/httpd:v0.1sha256:16913ce01fdceee9a389906cf385893120734b1a088b894cc5dce1a9ead252fd[root@localhost ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEsyblyw0806/httpd v0.1 16913ce01fdc 6 seconds ago 713MBbusybox latest d23834f29b38 6 days ago 1.24MBcentos latest 5d0da3dc9764 2 months ago 231MB部署nfs
需要开启一台新的虚拟机
[root@localhost ~]# yum -y install nfs-utils[root@localhost ~]# systemctl restart nfs-server.service[root@localhost ~]# mkdir /nfs[root@localhost ~]# chmod 777 /nfs/[root@localhost ~]# vim /etc/exports/nfs 192.168.200.136(rw)[root@localhost ~]# systemctl restart nfs-server
在有docker服务的虚拟机上一样安装nfs
[root@localhost ~]# yum -y install nfs-utils[root@localhost ~]# showmount -e 192.168.200.137Export list for 192.168.200.137:/nfs 192.168.200.136
挂载
[root@localhost ~]# mount -t nfs 192.168.200.137:/nfs /var/www/html/[root@localhost ~]# df -hFilesystem Size Used Avail Use% Mounted ondevtmpfs 883M 0 883M 0% /devtmpfs 901M 0 901M 0% /dev/shmtmpfs 901M 8.9M 892M 1% /runtmpfs 901M 0 901M 0% /sys/fs/cgroup/dev/mapper/rhel-root 47G 23G 25G 48% //dev/nvme0n1p1 1014M 179M 836M 18% /boottmpfs 181M 0 181M 0% /run/user/0overlay 47G 23G 25G 48% /var/lib/docker/overlay2/0a219b8bbb04290f6b1cc1ae29f5eb1a9bc713ff12c86c86c7e13d5c7ca63a0e/merged192.168.200.137:/nfs 47G 2.2G 45G 5% /var/www/html
创建容器并映射
[root@localhost ~]# docker run -itd --name httpd1 -p 80:80 -v /var/www/html/:/usr/local/apache/htdocs 16913ce01fdc42e38f1db61e49fafa0682125d0425e3d41c4f2db0f48e1973dee1905a90daf3[root@localhost ~]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES42e38f1db61e 16913ce01fdc "/bin/bash start.sh" 10 seconds ago Up 9 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp httpd1
上传我们要部署网站的代码
[root@localhost ~]# cd /var/www/html/[root@localhost html]# lsgame.html images index.html js style
此时在新开的一台虚拟机查看nfs
[root@localhost ~]# ls /nfs/game.html images index.html js style
访问测试


关于docker容器源码怎样部署httpd用存储卷部署网站就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
容器
源码
网站
存储
内容
文章
更多
知识
篇文章
镜像
不错
代码
注释
质量
新开
参考
帮助
有关
服务
测试
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
华服互联网科技怎么样
互联网金融监管科技数据
麻工互联网科技
互联网科技的发展
万易互联网科技
华中科技大学互联网
科技互联网公司logo
广西互联网科技公司
上海卓越科技 互联网
深圳前海聚择互联网科技有限公司
互联网科技热点资讯
互联网新科技动漫ppt素材
广州新华互联网科技学校电竞方面
互联网方面的科技前沿
雨阳互联网卡科技有限公司
江苏互联网科技小贷
广州互联网高科技取餐柜
互联网时代高科技布局
互联网企业和网络科技有限公司
小牛互联网科技有限公司地址
上海睿民互联网科技有限公司
互联网科技垄断
广州宏创互联网科技
互联网科技上市公司
互联网 视角下的科技创新
威龙国际互联网科技公司
沐思想互联网科技有限公司
福建互联网展示科技馆设计
互联网科技平台产品运营
湖北辰鑫科技互联网