skip to Main Content

I am trying to get up the keycloak instance via using keycloak, and the compose file I used is below which I get it from

https://github.com/keycloak/keycloak-containers/blob/main/docker-compose-examples/keycloak-postgres.yml

# keycloak dependencies

  postgres-keycloak:
    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:legacy
    environment:
      DB_VENDOR: POSTGRES
      DB_ADDR: postgres
      DB_DATABASE: keycloak
      DB_USER: keycloak
      DB_SCHEMA: public
      DB_PASSWORD: password
      KEYCLOAK_USER: admin
      KEYCLOAK_PASSWORD: admin
      # 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:
      - 8082:8082
    depends_on:
      - postgres-keycloak


volumes:
  postgres_data:
    driver: local

When I run the file I am getting connection errors as below :

backend_services-keycloak-1           | Caused by: javax.resource.ResourceException: IJ031084: Unable to create connection
backend_services-keycloak-1           | Caused by: org.postgresql.util.PSQLException: FATAL: password authentication failed for user "keycloak"
backend_services-keycloak-1           | 08:53:53,533 FATAL [org.keycloak.services] (ServerService Thread Pool -- 68) Error during startup: java.lang.RuntimeException: Failed to connect to database
backend_services-keycloak-1           | Caused by: javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:jboss/datasources/KeycloakDS
backend_services-keycloak-1           | 08:53:54,449 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([("subsystem" => "metrics")]): java.lang.NullPointerException
backend_services-keycloak-1           | 08:53:54,460 ERROR [org.jboss.as.server] (ServerService Thread Pool -- 45) WFLYSRV0022: Deploy of deployment "keycloak-server.war" was rolled back with no failure message

2

Answers


  1. This docker-compose.yml will be works.
    You did a wrong two places (DB_ADDR and port forwarding)

    version: '3'
    
    services:
      postgres-keycloak:
        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:legacy
        environment:
          DB_VENDOR: POSTGRES
          DB_ADDR: postgres-keycloak
          DB_DATABASE: keycloak
          DB_USER: keycloak
          DB_SCHEMA: public
          DB_PASSWORD: password
          KEYCLOAK_USER: admin
          KEYCLOAK_PASSWORD: admin
          # 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:
          - 8082:8080
        depends_on:
          - postgres-keycloak
    
    volumes:
      postgres_data:
        driver: local
    

    And open URL

    http://localhost:8082/auth/
    

    Click here then credential admin/admin (id / password)
    enter image description here

    enter image description here

    Login or Signup to reply.
  2. You can try this if you want, Application named test,

    Database login are, keycloak:password

    keycloak admin login is : root:root

    this will be accessible with a web browser at localhost:8080

    version: "3.8"
    name: test
    services:
        keycloak:
            image: jboss/keycloak:15.0.2
            environment:
                DB_VENDOR: POSTGRES
                DB_ADDR: postgres
                DB_DATABASE: keycloak
                DB_USER: keycloak
                DB_SCHEMA: public
                DB_PASSWORD: password
                KEYCLOAK_USER: root
                KEYCLOAK_PASSWORD: root
                KEYCLOAK_HOSTNAME: keycloak
                # 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   
            networks:
                - test
                
        postgres:
            image: postgres
            volumes:
                - postgres_data:/var/lib/postgresql/data
            environment:
                POSTGRES_DB: keycloak
                POSTGRES_USER: keycloak
                POSTGRES_PASSWORD: password
            networks:
                - test    
                
                
            
    volumes:
      postgres_data:
          driver: local  
          
    
    networks:
      test:
        driver: bridge
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search