【发布时间】:2021-08-23 14:51:44
【问题描述】:
我完全喜欢 docker 和 php 和 apache,我正在尝试在 docker 包含的 apache 上运行我的示例网站。它工作正常。我的dockerfile是这样的
From php:7.2-apache
Copy Site/ /var/www/html/
Run echo "ServerName localhost" >> /etc/apache2/apache2.conf
RUN docker-php-ext-install pdo pdo_mysql
Expose 80
如果我想在该 apache 上拥有另一个网站,例如“website1”,该怎么办。在 xampp 我可以更改 httpd.conf 文件并添加虚拟主机。但是我应该在 docker 容器中做什么?
更新
=============================================
我将文件更新如下,这是 docker-compose.yml
version: '3.9'
services:
apache:
build: .
container_name: php_cont
volumes:
- './apache2.conf:/etc/apache2/apache2.conf'
- './Site1/site1.conf:/etc/apache2/sites-available/site1.conf'
- './Site2/site2.conf:/etc/apache2/sites-available/site2.conf'
ports:
- '80:80'
这是 site.conf
<VirtualHost *:80>
DocumentRoot "d:\Temp\Site1"
ServerName site1Name
<Directory "d:\Temp\Site1">
</Directory>
</VirtualHost>
这是 site2.conf
<VirtualHost *:80>
DocumentRoot "d:\Temp\Site2"
ServerName site2Name
<Directory "d:\Temp\Site2">
</Directory>
</VirtualHost>
我将这两行添加到 windows=>system32=>driver=>etc 的 hosts 文件中
127.0.0.1 site1Name
127.0.0.1 site2Name
但是当我在浏览器上浏览到 site1Name 或 site2Name 时,没有成功
【问题讨论】:
标签: docker apache virtualhost