在端口进入状态之前达到错误超时 "inuse"

Error timeout reached before the port went into state "inuse"

将 postgresql 连接到 keycloak 时遇到问题。在 keycloak 中,我尝试在“KEYCLOAK_DATABASE_PORT”中使用 5433 和 5432 端口,但其中 none 不工作

docker撰写

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"

错误

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"

我不明白,为什么让 postgres 公开端口 5433 并配置 keycloak 以连接 5432

我采用了您的 docker-compose 示例并修复了端口分配。另外,我为 keycloak 服务器公开了端口 8080

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"

有效:

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 **