我试图在一台机器上创建多个Prisma数据库服务.我无法使用Docker Compose在3306以外的端口上创建MySQL数据库.
泊坞窗,compose.yml
version: '3'
services:
hackernews:
image: prismagraphql/prisma:1.8
restart: always
ports:
- "${CLIENT_PORT}:${INTERNAL_PORT}"
environment:
PRISMA_CONFIG: |
port: $INTERNAL_PORT
managementApiSecret: $PRISMA_MANAGEMENT_API_SECRET
databases:
default:
connector: MysqL
host: MysqL
port: $sql_INTERNAL_PORT
user: root
password: $sql_PASSWORD
migrations: true
MysqL:
image: MysqL:5.7
restart: always
environment:
MysqL_ROOT_PASSWORD: $sql_PASSWORD
volumes:
- ./custom/:/etc/MysqL/conf.d/my.cnf
- MysqL:/var/lib/MysqL
volumes:
MysqL:
泊坞窗,compose.override.yml
version: '3'
services:
MysqL:
expose:
- "${sql_INTERNAL_PORT}"
ports:
- "${sql_CLIENT_PORT}:${sql_INTERNAL_PORT}"
错误:
hackernews_1 | Exception in thread "main" java.sql.sqlTransientConnectionException: database - Connection is not available,request timed out after 5008ms.
hackernews_1 | at com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:548)
hackernews_1 | at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:186)
hackernews_1 | at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:145)
hackernews_1 | at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:83)
hackernews_1 | at slick.jdbc.hikaricp.HikariCPJdbcDataSource.createConnection(HikariCPJdbcDataSource.scala:18)
hackernews_1 | at slick.jdbc.JdbcBackend$BaseSession.sql.sqlNonTransientConnectionException: Could not connect to address=(host=MysqL)(port=3307)(type=master) : Connection refused (Connection refused)
hackernews_1 | at org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.get(ExceptionMapper.java:161)
hackernews_1 | at org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.connException(ExceptionMapper.java:79)
hackernews_1 | at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.connectWithoutProxy(AbstractConnectProtocol.java:1040)
hackernews_1 | at org.mariadb.jdbc.internal.util.Utils.retrieveProxy(Utils.java:490)
hackernews_1 | at org.mariadb.jdbc.MariaDbConnection.newConnection(MariaDbConnection.java:144)
hackernews_1 | at org.mariadb.jdbc.Driver.connect(Driver.java:90)
hackernews_1 | at slick.jdbc.DriverDataSource.getConnection(DriverDataSource.scala:101)
hackernews_1 | at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:341)
hackernews_1 | at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:193)
hackernews_1 | at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:430)
hackernews_1 | at com.zaxxer.hikari.pool.HikariPool.access$500(HikariPool.java:64)
hackernews_1 | at com.zaxxer.hikari.pool.HikariPool$PoolEntryCreator.call(HikariPool.java:570)
hackernews_1 | at com.zaxxer.hikari.pool.HikariPool$PoolEntryCreator.call(HikariPool.java:563)
hackernews_1 | at java.util.concurrent.FutureTask.run(FutureTask.java:266)
码头工人
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ab721996469d MysqL:5.7 "docker-entrypoint.s…" 42 minutes ago Up 55 seconds 3306/tcp,0.0.0.0:3307->3307/tcp two_MysqL_1
7aab98e2b8d7 prismagraphql/prisma:1.8 "/bin/sh -c /app/sta…" 2 hours ago Restarting (1) Less than a second ago two_hackernews_1
.ENV
sql_PASSWORD=myuniquepassword
sql_INTERNAL_PORT=3307
sql_CLIENT_PORT=3307
最佳答案
变量sql_INTERNAL_PORT可能具有3307值.您需要将其更改为3306.
原文链接:https://www.f2er.com/docker/436047.html此外,您可以删除
expose:
- "${sql_INTERNAL_PORT}"
线. MysqL已经公开了3306端口.
集群中的所有应用程序都使用内部端口(在MysqL情况下为3306).外部端口(在部分端口中)只需要外部字通信.
如果你想拥有几个数据库,你需要更改docker-compose这样的东西:
version: '3'
services:
hackernews:
image: prismagraphql/prisma:1.8
restart: always
ports:
- "${CLIENT_PORT}:${INTERNAL_PORT}"
environment:
PRISMA_CONFIG: |
port: $INTERNAL_PORT
managementApiSecret: $PRISMA_MANAGEMENT_API_SECRET
databases:
default:
connector: MysqL
host: MysqL_first
port: 3306
user: root
password: $sql_PASSWORD
migrations: true
second:
connector: MysqL
host: MysqL_second
port: 3306
user: root
password: $sql_PASSWORD
migrations: true
MysqL_first:
image: MysqL:5.7
restart: always
environment:
MysqL_ROOT_PASSWORD: $sql_PASSWORD
ports:
- 3307:3306
volumes:
- ./custom/:/etc/MysqL/conf.d/my.cnf
- MysqL:/var/lib/MysqL
MysqL_second:
image: MysqL:5.7
restart: always
environment:
ports:
- 3308:3306
MysqL_ROOT_PASSWORD: $sql_PASSWORD