简体   繁体   中英

Testcontainer Keycloak does not connect to Testcontainer 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM