我正在使用docker-compose,并且我在Nginx + PHP-FPM上有一个带有很多虚拟主机的开发服务器。目前,nginx容器可以处理多个虚拟主机:
version: '3'
services:
nginx-proxy:
image: nginx:1.17.4-alpine
container_name: nginx-proxy
ports:
- '80:80'
- '443:443'
volumes:
- conf:/etc/nginx/conf.d
- vhost:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
- certs:/etc/nginx/certs:ro
labels:
- 'com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true'
restart: always
dockergen:
[...]
letsencrypt:
[...]
nginx:
image: nginx:1.17.4-alpine
restart: always
container_name: nginx
environment:
VIRTUAL_HOST: proj1.site.com,proj2.example.com
LETSENCRYPT_HOST: proj1.site.com,proj2.example.com
LETSENCRYPT_EMAIL: tech@example.com
volumes:
- './proj1:/proj1'
- './proj2:/proj2'
- './site.conf:/etc/nginx/conf.d/site.conf'
php:
build:
context: ./php
container_name: php
volumes:
- './proj1:/proj1'
- './proj2:/proj2'
restart: always
volumes:
conf:
vhost:
html:
certs:
networks:
default:
external:
name: nginx-proxy
现在,我想分离虚拟主机容器,因为我需要注入不同的env文件。我应该为每个项目复制nginx容器(当然使用不同的名称)和site.conf吗?我做对了吗?您能给我建议正确的方向吗?附言我读过docker-compose v3不推荐使用extends关键字,因此,如果可能的话,我想避免这种情况。