英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论