测试容器(Testcontainer)中的Keycloak无法连接到Testcontainer中的PostgreSQL。

huangapple go评论76阅读模式
英文:

Testcontainer Keycloak does not connect to Testcontainer PostgreSQL

问题

我正在部署两个Testcontainers,一个使用PostgreSQL(12.0)镜像,另一个使用Keycloak(8.0.0)镜像。

PostgreSQL部分成功启动,但是当Keycloak尝试连接到PostgreSQL时,返回连接被拒绝的错误。

我已经将所有的环境变量都设置给了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容器的别名。

我是否遗漏了什么?
是否有其他人尝试过并获得了成功?

提前致谢。

英文:

I am deploying two Testcontainers, one with an image of PostgreSQL (12.0) and another one with Keycloak (8.0.0).

The PostgreSQL one starts successfully, but when the Keycloak one tries to connect to PostgreSQL returns a connection refused.

I put all the environment variables to Keycloak to connect to that PostgreSQL container

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);

where ${DB_PORT} is the port where the PostgreSQL is deployed and the DB_ADDR is the alias that PostgreSQL container has in a network that I made, where are both containers.

Am I missing something?
Has anyone tried too with success?

Thanks in advance.

答案1

得分: 1

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

英文:

${DB_PORT} must be 5432, since you connect directly to the container and not through the exposed port.

huangapple
  • 本文由 发表于 2020年4月9日 00:44:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/61105722.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定