我有一个网站托管在生产共享主机上。该网站通过代码中的localhost
连接到数据库。在我的docker-compose中,我有一个php:5.6-apache
和mysql:5.6
实例。Docker-compose端口转发
有无论如何告诉docker-compose将Web容器端口上的端口3306转发给db容器上的3306,以便当web容器连接到3306上的localhost时,它将被发送到3306上的db,将Web容器上的端口80共享给外部世界?
当前泊坞窗,compose.yml:
version: "3"
services:
web:
build: .
#image: php:5.6-apache
ports:
- "8080:80"
environment:
- "APP_LOG=php://stderr"
- "LOG_LEVEL=debug"
volumes:
- .:/var/www/html
network_mode: service:db # See https://stackoverflow.com/a/45458460/95195
# networks:
# - internal
working_dir: /var/www
db:
image: mysql:5.6
ports:
- "3306:3306"
environment:
- "MYSQL_XXXXX=*****"
volumes:
- ./provision/mysql/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
# networks:
# - internal
networks:
internal:
driver: bridge
当前出错:
ERROR: for web Cannot create container for service web: conflicting options: port publishing and the container type network mode
看来这个标志与端口不兼容。我想这样做,但也有Web容器端口80可访问世界。我无法准确理解network_mode:service如何从文档中执行操作。 –
更新了有关端口的更多详细信息。见upate –