【发布时间】:2020-04-14 16:13:23
【问题描述】:
我已经构建了一个包含 3 个服务的 docker-compose:db、nginx、selenium。
使用 nginx 托管的应用程序与数据库通信 (nginx db),并且 selenium 测试应用程序 (selenium -> app)。
version: '3'
services:
nginx:
image: <my_private_repo>/nginx
...
db:
image: <my_private_repo>/db
# nginx cannot communicate with db after I remove exposing port 3306
ports:
- "3306:3306"
...
selenium:
image: joyzoursky/python-chromedriver:3.8-selenium
command: "bash seleniumScript.sh"
depends_on:
- nginx
- db
我使用docker-compose run selenium 运行我的测试
当我暴露数据库端口时一切正常,但当我停止暴露端口 3306 时,nginx 无法与数据库通信。
我的理解是,一个 docker-compose 设置中的所有服务都是自动连接的,用户不需要创建任何额外的网络,但我显然错了。
我的问题是我应该如何设置服务之间的公开端口而不将它们暴露给主机?
更新:
我的 nginx 应用程序已将数据库主机配置为服务名称 db。 Selenium 脚本设置使用 db 主机填充数据库并通过 https://nginx url 测试 nginx 应用程序。
【问题讨论】:
标签: docker-compose docker-networking