Faced a problem with connection of postgresql to keycloak. In keycloak I tried to use 5433 and 5432 port in "KEYCLOAK_DATABASE_PORT
", but none of them is not working
docker compose
version: "3.8"
volumes:
postgres_data:
driver: local
services:
postgres:
container_name: postgres.beltweet.com
image: library/postgres
volumes:
- postgres_data:/var/lib/postgresql/data
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: beltweet
ports:
- "5433:5432"
restart: unless-stopped
keycloak:
image: docker.io/bitnami/keycloak:latest
container_name: keycloak.beltweet.com
environment:
KEYCLOAK_ADMIN_USER: admin
KEYCLOAK_ADMIN_PASSWORD: 260
KEYCLOAK_MANAGEMENT_PASSWORD: 260
KEYCLOAK_DATABASE_PORT: 5432
KEYCLOAK_DATABASE_HOST: postgres
KEYCLOAK_DATABASE_NAME: beltweet
KEYCLOAK_CREATE_ADMIN_USER: 'true'
KEYCLOAK_DATABASE_USER: postgres
KEYCLOAK_DATABASE_PASSWORD: postgres
KEYCLOAK_HTTP_PORT: 3033
KEYCLOAK_HTTPS_PORT: 3034
KEYCLOAK_JGROUPS_DISCOVERY_PROTOCOL: JDBC_PING
KEYCLOAK_CACHE_OWNERS_COUNT: 3
KEYCLOAK_AUTH_CACHE_OWNERS_COUNT: 3
depends_on:
postgres:
condition: service_started
links:
- "postgres:postgres"
error
Starting postgres.beltweet.com ... done
Recreating keycloak.beltweet.com ... done
Attaching to postgres.beltweet.com, keycloak.beltweet.com
postgres.beltweet.com |
postgres.beltweet.com | PostgreSQL Database directory appears to contain a database; Skipping initialization
postgres.beltweet.com |
postgres.beltweet.com | 2022-03-17 14:33:35.516 UTC [1] LOG: starting PostgreSQL 14.2 (Debian 14.2-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
keycloak.beltweet.com | keycloak 14:33:35.99
keycloak.beltweet.com | keycloak 14:33:35.99 Welcome to the Bitnami keycloak container
postgres.beltweet.com | 2022-03-17 14:33:35.516 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
postgres.beltweet.com | 2022-03-17 14:33:35.516 UTC [1] LOG: listening on IPv6 address "::", port 5432
postgres.beltweet.com | 2022-03-17 14:33:35.517 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres.beltweet.com | 2022-03-17 14:33:35.520 UTC [26] LOG: database system was shut down at 2022-03-17 14:33:30 UTC
postgres.beltweet.com | 2022-03-17 14:33:35.523 UTC [1] LOG: database system is ready to accept connections
keycloak.beltweet.com | keycloak 14:33:35.99 Subscribe to project updates by watching https://github.com/bitnami/bitnami-docker-keycloak
keycloak.beltweet.com | keycloak 14:33:36.00 Submit issues and feature requests at https://github.com/bitnami/bitnami-docker-keycloak/issues
keycloak.beltweet.com | keycloak 14:33:36.00
keycloak.beltweet.com | keycloak 14:33:36.00 INFO ==> ** Starting keycloak setup **
keycloak.beltweet.com | keycloak 14:33:36.01 INFO ==> Validating settings in KEYCLOAK_* env vars...
keycloak.beltweet.com | keycloak 14:33:36.02 INFO ==> Trying to connect to PostgreSQL server postgres...
keycloak.beltweet.com | timeout reached before the port went into state "inuse"
keycloak.beltweet.com | timeout reached before the port went into state "inuse"
keycloak.beltweet.com | timeout reached before the port went into state "inuse"
keycloak.beltweet.com | timeout reached before the port went into state "inuse"
keycloak.beltweet.com | timeout reached before the port went into state "inuse"
keycloak.beltweet.com | timeout reached before the port went into state "inuse"
I do not understand, why you let postgres expose port 5433
and configure keycloak to connect on 5432
.
I took your docker-compose example and fixed the port assignment. Additionally I exposed port 8080
for keycloak server:
version: "3.8"
volumes:
postgres_data:
driver: local
services:
postgres:
container_name: postgres.beltweet.com
image: library/postgres
volumes:
- postgres_data:/var/lib/postgresql/data
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: beltweet
ports:
- "5432:5432"
restart: unless-stopped
keycloak:
image: docker.io/bitnami/keycloak:latest
container_name: keycloak.beltweet.com
ports:
- "8080:8080"
environment:
KEYCLOAK_ADMIN_USER: admin
KEYCLOAK_ADMIN_PASSWORD: 260
KEYCLOAK_MANAGEMENT_PASSWORD: 260
KEYCLOAK_DATABASE_PORT: 5432
KEYCLOAK_DATABASE_HOST: postgres
KEYCLOAK_DATABASE_NAME: beltweet
KEYCLOAK_CREATE_ADMIN_USER: 'true'
KEYCLOAK_DATABASE_USER: postgres
KEYCLOAK_DATABASE_PASSWORD: postgres
KEYCLOAK_HTTP_PORT: 3033
KEYCLOAK_HTTPS_PORT: 3034
KEYCLOAK_JGROUPS_DISCOVERY_PROTOCOL: JDBC_PING
KEYCLOAK_CACHE_OWNERS_COUNT: 3
KEYCLOAK_AUTH_CACHE_OWNERS_COUNT: 3
depends_on:
postgres:
condition: service_started
links:
- "postgres:postgres"
It works:
keycloak.beltweet.com | keycloak 12:47:54.29 INFO ==> Trying to connect to PostgreSQL server postgres...
keycloak.beltweet.com | keycloak 12:47:54.29 INFO ==> Found PostgreSQL server listening at postgres:5432
keycloak.beltweet.com | keycloak 12:47:54.30 INFO ==> Configuring database settings
keycloak.beltweet.com | keycloak 12:48:05.96 INFO ==> Configuring jgroups settings
keycloak.beltweet.com | keycloak 12:48:10.89 INFO ==> Configuring cache count
keycloak.beltweet.com | keycloak 12:48:15.94 INFO ==> Configuring authentication cache count
keycloak.beltweet.com | keycloak 12:48:22.87 INFO ==> Configuring log level
keycloak.beltweet.com | keycloak 12:48:27.71 INFO ==> Configuring proxy address forwarding
keycloak.beltweet.com | keycloak 12:48:32.68 INFO ==> Configuring node identifier
keycloak.beltweet.com |
keycloak.beltweet.com | keycloak 12:48:37.33 INFO ==> ** keycloak setup finished! **
keycloak.beltweet.com | keycloak 12:48:37.35 INFO ==> ** Starting keycloak **