多个 docker-compose 共享网络,共享卷
编辑于 2022-04-09 22:50:27 阅读 1677
server/docker-compose1.yml
version: '3'
networks:
web-network:
volumes:
www-data:
services:
docker-nginx:
image: nginx:1.21.3
hostname: nginx
ports:
- "81:80"
restart: always
tty: true
volumes:
- www-data:/var/www/html
networks:
- web-network
server/docker-compose2.yml
version: '3'
# 外部网络
networks:
server_web-network:
external: true
# 外部卷 https://stackoverflow.com/questions/54051130/share-volumes-between-separate-docker-compose-files
volumes:
server_www-data:
external: true
services:
docker-nginx2:
image: nginx:1.21.3
hostname: nginx2
ports:
- "82:80"
restart: always
tty: true
volumes:
- server_www-data:/var/www/html
networks:
- server_web-network