Testcontainer Keycloak 不连接到 Testcontainer PostgreSQL

Testcontainer Keycloak does not connect to Testcontainer PostgreSQL

我正在部署两个 Testcontainer,一个带有 PostgreSQL (12.0) 的映像,另一个带有 Keycloak (8.0.0)。

PostgreSQL 成功启动,但是当 Keycloak 尝试连接到 PostgreSQL 时returns连接被拒绝。

我将所有环境变量都放到 Keycloak 中以连接到那个 PostgreSQL 容器

withEnv("DB_VENDOR", "postgres");
withEnv("DB_DATABASE", KeycloakDS);
withEnv("DB_SCHEMA", test);
withEnv("DB_USER", postgres);
withEnv("DB_PASSWORD", keycloak);
withEnv("DB_ADDR", postgres);
withEnv("DB_PORT", ${DB_PORT});
withEnv("KEYCLOAK_USER", admin);
withEnv("KEYCLOAK_PASSWORD", admin);

其中 ${DB_PORT} 是部署 PostgreSQL 的端口,DB_ADDR 是 PostgreSQL 容器在我创建的网络中的别名,两个容器都在哪里。

我错过了什么吗? 有没有人也试过成功?

提前致谢。

${DB_PORT} 必须是 5432,因为您直接连接到容器而不是通过暴露的端口。