Docker 在 Azure 中撰写:无法连接到数据库
Docker compose in Azure: Can't connect to database
我正在尝试在 Azure 容器实例中将 SteVe OCPP server 变为 运行。但是在 Azure ACI 上下文中 运行ning docker-compose up
时,Web 应用程序不会连接到数据库。 运行在当地还好。
这是 docker 撰写文件:
version: "3.0"
volumes:
db-data:
external: false
services:
db:
image: mariadb:10.4
ports:
- 3306:3306
environment:
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
MYSQL_DATABASE: stevedb
MYSQL_USER: steve
MYSQL_PASSWORD: changeme
web:
image: rainmakers/steve:latest
links:
- "db:mariadb"
ports:
- 8180:8180
- 8443:8443
depends_on:
- db
这是我在 Web 服务日志中得到的唯一内容:
2021/11/23 13:20:57 Waiting for: tcp://mariadb:3306
2021/11/23 13:20:57 Problem with dial: dial tcp: lookup mariadb on 168.63.129.16:53: no such host. Sleeping 1s
2021/11/23 13:20:58 Problem with dial: dial tcp: lookup mariadb on 168.63.129.16:53: no such host. Sleeping 1s
2021/11/23 13:20:59 Problem with dial: dial tcp: lookup mariadb on 168.63.129.16:53: no such host. Sleeping 1s
2021/11/23 13:21:00 Problem with dial: dial tcp: lookup mariadb on 168.63.129.16:53: no such host. Sleeping 1s
2021/11/23 13:21:01 Problem with dial: dial tcp: lookup mariadb on 168.63.129.16:53: no such host. Sleeping 1s
2021/11/23 13:21:02 Problem with dial: dial tcp: lookup mariadb on 168.63.129.16:53: no such host. Sleeping 1s
2021/11/23 13:21:03 Problem with dial: dial tcp: lookup mariadb on 168.63.129.16:53: no such host. Sleeping 1s
这会持续一分钟,然后服务终止。
知道如何继续吗?
我猜你应该连接 http://db:3306
而不是 mariadb:3306
。
默认情况下 Docker Compose
版本 3 使用服务名称作为 inter-container networking 的主机名。
我正在尝试在 Azure 容器实例中将 SteVe OCPP server 变为 运行。但是在 Azure ACI 上下文中 运行ning docker-compose up
时,Web 应用程序不会连接到数据库。 运行在当地还好。
这是 docker 撰写文件:
version: "3.0"
volumes:
db-data:
external: false
services:
db:
image: mariadb:10.4
ports:
- 3306:3306
environment:
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
MYSQL_DATABASE: stevedb
MYSQL_USER: steve
MYSQL_PASSWORD: changeme
web:
image: rainmakers/steve:latest
links:
- "db:mariadb"
ports:
- 8180:8180
- 8443:8443
depends_on:
- db
这是我在 Web 服务日志中得到的唯一内容:
2021/11/23 13:20:57 Waiting for: tcp://mariadb:3306
2021/11/23 13:20:57 Problem with dial: dial tcp: lookup mariadb on 168.63.129.16:53: no such host. Sleeping 1s
2021/11/23 13:20:58 Problem with dial: dial tcp: lookup mariadb on 168.63.129.16:53: no such host. Sleeping 1s
2021/11/23 13:20:59 Problem with dial: dial tcp: lookup mariadb on 168.63.129.16:53: no such host. Sleeping 1s
2021/11/23 13:21:00 Problem with dial: dial tcp: lookup mariadb on 168.63.129.16:53: no such host. Sleeping 1s
2021/11/23 13:21:01 Problem with dial: dial tcp: lookup mariadb on 168.63.129.16:53: no such host. Sleeping 1s
2021/11/23 13:21:02 Problem with dial: dial tcp: lookup mariadb on 168.63.129.16:53: no such host. Sleeping 1s
2021/11/23 13:21:03 Problem with dial: dial tcp: lookup mariadb on 168.63.129.16:53: no such host. Sleeping 1s
这会持续一分钟,然后服务终止。
知道如何继续吗?
我猜你应该连接 http://db:3306
而不是 mariadb:3306
。
默认情况下 Docker Compose
版本 3 使用服务名称作为 inter-container networking 的主机名。