Docker-compose 安装编排httpd

本文介绍了如何使用docker-compose来安装和编排httpd服务,以部署静态HTML页面。通过修改docker-compose.yml文件的卷挂载配置,可以实现多个独立的HTML项目在同一httpd容器中分别访问。步骤包括创建目录、编写docker-compose.yml、解压HTML资源、启动服务,并展示了如何通过改变目录结构来部署多个web项目。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

httpd安装编排

最近写了一个纯html的网页想让别人也看到那就要部署一下,所以今天介绍一下啊httpd部署html静态页面的过程

1.创建目录 mkdir web-html
2.编写docker-compose.yml文件

docker-compose.yml

version: '3'
services:
    web:
        container_name: web-httpd
        image: httpd
        ports:
            - "8080:80"
        privileged: true
        restart: always #重启docker时,自动启动相关容器
        volumes:
            - "./resume/:/usr/local/apache2/htdocs/"

实操命令

[root@localhost software]# mkdir web-html   # 创建目录
[root@localhost software]# ll
total 0
drwxr-xr-x. 2 root root 24 May  7 00:01 web-html
[root@localhost software]# cd web-html/
[root@localhost web-html]# ll
total 1560
-rw-r--r--. 1 root root 1596144 May  7 00:01 resume.zip    # 上传html资源
[root@localhost web-html]# unzip resume.zip       #解压
[root@localhost web-html]# ll
total 1560
drwxr-xr-x. 3 root root      38 May  7 00:02 resume
-rw-r--r--. 1 root root 1596144 May  7 00:01 resume.zip
[root@localhost web-html]# cd resume/          
[root@localhost resume]# ll
total 24
drwxr-xr-x. 6 root root    54 Apr 28 16:57 assets
-rw-r--r--. 1 root root 21282 Apr 28 16:37 index.html
[root@localhost resume]# cd ..
[root@localhost web-html]# vim docker-compose.yml
[root@localhost web-html]# ll
total 1564
-rw-r--r--. 1 root root     222 May  7 00:05 docker-compose.yml
drwxr-xr-x. 3 root root      38 May  7 00:02 resume
-rw-r--r--. 1 root root 1596144 May  7 00:01 resume.zip
[root@localhost web-html]# docker-compose up -d

内容扩展

例如现我们改动docker-compose.yml里volumes: 的配置参数,改动后配置如下
volumes: - “./web/:/usr/local/apache2/htdocs/”
在docker-compose.yml文件的同级目录下创建文件结构如下:
├─web
│ ├─web01-html
│ │ │index.html
│ ├─web02-html
│ │ │index.html
│ ├─web03-html
│ │ │index.html

扩展实操

[root@localhost web-html]# ll
total 1564
-rw-r--r--. 1 root root     222 May  7 00:05 docker-compose.yml
drwxr-xr-x. 2 root root      24 May  7 00:01 web
[root@localhost web-html]# cd web
[root@localhost web]# ll
drwxr-xr-x. 2 root root      24 May  7 00:10 web01-html
drwxr-xr-x. 2 root root      24 May  7 00:10 web02-html
drwxr-xr-x. 2 root root      24 May  7 00:11 web03-html
[root@localhost web-html]# cd web01-html                 # 其它web02-html、web02-html文件也是如此
[root@localhost web01-html]# ll
-rw-r--r--. 1 root root 21282 Apr 28 16:37 index.html

这样的目录结构,web01-html、web02-html、web03-html 都是一个单独的html的web项目

访问 :web01-html :http://ip:8080/web01-html

访问 :web02-html :http://ip:8080/web02-html

访问 :web03-html :http://ip:8080/web03-html

最后

至此便是使用Docker-compose 安装编排httpd的过程,希望能给您带去帮助!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值