skip to Main Content

I am working with docker-compose and I am trying to deploy it on a VPS Centos 8 but keycloak can’t access to the postgres database.
However I can connect to the database with pgAdmin.

I have those following errors :

    Caused by: java.net.NoRouteToHostException: No route to host (Host unreachable)
            at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
            at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399)
            at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242)
            at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224)
            at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:403)
            at java.base/java.net.Socket.connect(Socket.java:609)
            at [email protected]//org.postgresql.core.PGStream.<init>(PGStream.java:70)
            at [email protected]//org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:91)
            at [email protected]//org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:192)
            ... 62 more
    
    13:34:55,281 FATAL [org.keycloak.services] (ServerService Thread Pool -- 65) java.lang.RuntimeException: Failed to connect to database

and

    13:34:56,307 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([("subsyste                                                                                                                                         m" => "microprofile-metrics-smallrye")]): java.lang.NullPointerException
            at [email protected]//org.wildfly.extension.microprofile.metrics.MicroProfileMetricsSubsystemAdd$                                                                                                                                         2.execute(MicroProfileMetricsSubsystemAdd.java:86)
            at [email protected]//org.jboss.as.controller.AbstractOperationContext.executeStep(AbstractOperationContext.java:999)
            at [email protected]//org.jboss.as.controller.AbstractOperationContext.processStages(AbstractOperationContext.java:743)
            at [email protected]//org.jboss.as.controller.AbstractOperationContext.executeOperation(AbstractOperationContext.java:467)
            at [email protected]//org.jboss.as.controller.OperationContextImpl.executeOperation(OperationContextImpl.java:1413)
            at [email protected]//org.jboss.as.controller.ModelControllerImpl.boot(ModelControllerImpl.java:527)
            at [email protected]//org.jboss.as.controller.AbstractControllerService.boot(AbstractControllerService.java:515)
            at [email protected]//org.jboss.as.controller.AbstractControllerService.boot(AbstractControllerService.java:477)
            at [email protected]//org.jboss.as.server.ServerService.boot(ServerService.java:448)
            at [email protected]//org.jboss.as.server.ServerService.boot(ServerService.java:401)
            at [email protected]//org.jboss.as.controller.AbstractControllerService$1.run(AbstractControllerService.java:416)
            at java.base/java.lang.Thread.run(Thread.java:834)

This is my docker-compose.yml :

    version: "3.7"
    
    services: 
    
      keycloak: 
        container_name: app-keycloak
        depends_on: 
          - postgres
        environment: 
          # Admin account
          KEYCLOAK_USER: foo
          KEYCLOAK_PASSWORD: foo
          #KEYCLOAK_IMPORT: /tmp/realm-export.json
           
          # PostgreSQL DB settings
          DB_VENDOR: POSTGRES
          DB_ADDR: postgres
          DB_PORT: 5432
          DB_DATABASE: foo
          DB_SCHEMA: public
          DB_USER: foo
          DB_PASSWORD: foo
        image: "jboss/keycloak:10.0.2"
        ports: 
          - "9999:8080"
        restart: always
        networks:
          - auth-network
    
      postgres: 
        container_name: app-postgres
        environment: 
          POSTGRES_DB: foo
          POSTGRES_PASSWORD: foo
          POSTGRES_USER: foo
        image: "postgres:13-alpine"
        ports: 
          - "5432:5432"
        restart: always
        volumes: 
          - "./volumes/postgres-data:/var/lib/postgresql/data"
        networks:
          - auth-network
    
    networks:   auth-network:
        driver: bridge

Do you have any ideas of how I can resolve this ?

2

Answers


  1. Chosen as BEST ANSWER

    With my my Windows 10 PC, that solution work but I still have thoses errors on my VPS Centos 8. Do you have others ideas ?

    firewall-cmd --zone=public --list-all

    public (active)
      target: default
      icmp-block-inversion: no
      interfaces: eth0
      sources:
      services: cockpit dhcpv6-client https ssh
      ports: 8077/tcp 27017/tcp 8081/tcp 9999/tcp 5432/tcp 8443/tcp 8080/tcp
      protocols:
      masquerade: no
      forward-ports:
      source-ports:
      icmp-blocks:
      rich rules:
    

  2. Working example for me

    version: '3'
    
    volumes:
      postgres_data:
          driver: local
    
    services:
      postgres:
          image: postgres
          volumes:
            - postgres_data:/var/lib/postgresql/data
          environment:
            POSTGRES_DB: keycloak
            POSTGRES_USER: keycloak
            POSTGRES_PASSWORD: password
      keycloak:
          image: quay.io/keycloak/keycloak:latest
          environment:
            DB_VENDOR: POSTGRES
            DB_ADDR: postgres
            DB_DATABASE: keycloak
            DB_USER: keycloak
            DB_SCHEMA: public
            DB_PASSWORD: password
            KEYCLOAK_USER: admin
            KEYCLOAK_PASSWORD: Pa55w0rd
            # Uncomment the line below if you want to specify JDBC parameters. The parameter below is just an example, and it shouldn't be used in production without knowledge. It is highly recommended that you read the PostgreSQL JDBC driver documentation in order to use it.
            #JDBC_PARAMS: "ssl=true"
          ports:
            - 8080:8080
          depends_on:
            - postgres
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search