大家好,我是蒸汽新手,我尝试使用 fluent 将 docker 容器中的 Vapor 应用程序连接到另一个 docker 容器中的 MySQL 数据库,但出现以下错误
unknown(host: "mysql_host", port: 3306)
Swift/ErrorType.swift:200: Fatal error: Error raised at top level:
NIO.SocketAddressError.unknown(host: "mysql_host", port: 3306)
这是我在 configure.swift 上的配置:
app.databases.use(.mysql(hostname:"mysql_net",
username:"sergio",
password:"holaMundo",
database:"vapor",
tlsConfiguration: .forClient(certificateVerification: .none)), as: .mysql)
这是我的码头工人撰写:
version: '3.7'
services:
mysql:
build:
context: .
dockerfile: Dockerfile
container_name: bd
restart: always
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: "holaMundo"
MYSQL_DATABASE: "vapor"
MYSQL_USER: "sergio"
MYSQL_PASSWORD: "holaMundo"
volumes:
- ./schemas:/var/lib/mysql:rw
networks:
mysql_network:
aliases:
- mysql_host
volumes:
schemas: {}
networks:
mysql_network:
name: mysql_net
driver: bridge