Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
721 views
in Technique[技术] by (71.8m points)

keycloak docker installation issue with MySQL

Im using following docker-compose to start containers for mysql and keycloak. I need to use mysql for keycloak. When I use below docker-compose it shows below error. it gets stuck either at 'starting keycloak deployment' or 'Bound datasource KeycloakDS'

Im installing it on ubuntu.

Note: The docker compose (mentioned below) is all what Im executing. Im not very sure if I need mysql jdbc connector to install? If yes , how to install mysql connector for keycloak in docker? Im aware how to configure it for non docker env.

Will appreciate your help/suggestions on this issue.

error

keycloak_1  | 17:10:38,378 INFO  [org.jboss.modcluster] (ServerService Thread Pool -- 63) MODCLUSTER000032: Listening to proxy advertisements on /224.0.1.105:23364
keycloak_1  | 17:10:40,864 INFO  [org.jboss.as.server.deployment.scanner] (MSC service thread 1-2) WFLYDS0013: Started FileSystemDeploymentService for directory /opt/jboss/keycloak/standalone/deployments
keycloak_1  | 17:10:54,907 **INFO  [org.jboss.as.server.deployment] (MSC service thread 1-1) WFLYSRV0027: Starting deployment of "keycloak-server.war" (runtime-name: "keycloak-server.war")
keycloak_1  | 17:15:21,570 ERROR [org.jboss.as.controller.management-operation] (Controller Boot** Thread) WFLYCTL0348: Timeout after [300] seconds waiting for service container stability. Operation will roll back. Step that first updated the service container was 'add' at address '[

or sometime at
keycloak_1  | 17:58:57,769 INFO  [org.jboss.as.server.deployment.scanner] (MSC service thread 1-1) WFLYDS0013: Started FileSystemDeploymentService for directory /opt/jboss/keycloak/standalone/deployments
keycloak_1  | 17:58:57,796 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) WFLYSRV0027: Starting deployment of "keycloak-server.war" (runtime-name: "keycloak-server.war")
keycloak_1  | 17:58:58,663 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-2) WFLYUT0006: Undertow HTTPS listener https listening on 0.0.0.0:8443
keycloak_1  | 17:58:58,702 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-2) WFLYJCA0001: Bound data source [java:jboss/datasources/ExampleDS]
keycloak_1  | 17:58:58,711 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-2) WFLYJCA0001: Bound data source [java:jboss/datasources/KeycloakDS]

docker-compose.yml

version: '3.7'

services:
  # Database
  db:
    image: mysql:8.0.23
    volumes:
     - /var/lib/mysql_data:/var/lib/mysql
     - ./config-file.cnf:/etc/mysql/conf.d/config-file.cnf
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: MYDB
      MYSQL_USER: testusr
      MYSQL_PASSWORD: password
    expose:
      - '3306'
    ports:
      - '3306:3306'
    networks:
      - mysqlnet
  # Keycloak
  keycloak:
    depends_on:
      - db
    image: jboss/keycloak:12.0.2
    restart: always
    environment:
        DB_VENDOR: MYSQL
        DB_DATABASE: KEYCLOAK
        DB_USER: keycloak
        DB_PASSWORD: password
        KEYCLOAK_USER: admin
        KEYCLOAK_PASSWORD: password
        JDBC_PARAMS: "connectTimeout=30000"
    expose:
      - '8181'
    ports:
      - '8181:8080'
    networks:
      - mysqlnet
networks:
  mysqlnet:

updated docker-compose. but it is also getting stuck . Am I missing anything?

keycloak_1  | 16:30:40,800 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 64) WFLYCLINF0002: Started realms cache from keycloak container
keycloak_1  | 16:30:40,803 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 67) WFLYCLINF0002: Started users cache from keycloak container
keycloak_1  | 16:30:40,802 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 62) WFLYCLINF0002: Started keys cache from keycloak container
keycloak_1  | 16:30:40,803 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 68) WFLYCLINF0002: Started authorization cache from keycloak container
keycloak_1  | 16:30:41,162 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-1) WFLYSRV0273: Excluded subsystem webservices via jboss-deployment-structure.xml does not exist.
keycloak_1  | 16:33:49,638 INFO  [org.keycloak.services] (ServerService Thread Pool -- 67) KC-SERVICES0001: Loading config from standalone.xml or domain.xml

docker-compose

version: '3'
volumes:
  mysql_data:
services:
  mysql:
      image: mysql:8.0.23
      volumes:
        - mysql_data:/var/lib/mysql
      restart: always
      environment:
        MYSQL_ROOT_PASSWORD: rootpassword
        MYSQL_DATABASE: keycloak
        MYSQL_USER: keycloak
        MYSQL_PASSWORD: password
      expose:
        - 3306
      ports:
        - 3306:3306
  keycloak:
      image: jboss/keycloak:12.0.2
      restart: always
      environment:
        DB_VENDOR: MYSQL
        DB_ADDR: mysql
        DB_DATABASE: keycloak
        DB_USER: keycloak
        DB_PASSWORD: password
        KEYCLOAK_USER: admin
        KEYCLOAK_PASSWORD: password
        JDBC_PARAMS: "connectTimeout=1000,useSSL=false"
      ports:
        - 8080:8080
      expose:
        - 8080
      depends_on:
        - mysql

Finally resolved:

  1. the final docker compose file: https://github.com/awstechguide/scripts/blob/master/docker/docker-compose/docker-compose-keycloak-mysql-phpmyadmin.yml

  2. I was using t2.micro instance earlier. due to that the keycloak process was getting stuck frequently. When I changed to a bigger instance (t2.medium) it worked fine.

question from:https://stackoverflow.com/questions/65850151/keycloak-docker-installation-issue-with-mysql

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Obvious problems in your config:

1.) DB credentials are not matching, it should be:

  db:
...
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: MYDB
      MYSQL_USER: testusr
      MYSQL_PASSWORD: password
...
  keycloak:
...
    environment:
        DB_VENDOR: MYSQL
        DB_DATABASE: MYDB
        DB_USER: testusr
        DB_PASSWORD: password
...

2.) You are not pointing Keycloak to DB service:

  db:
...
  keycloak:
...
    environment:
        DB_ADDR: db
...

Those are obvious error, but there can be more problems.

I would expose port 8443 from the container instead of 8080 - it has enabled https with self signed cert.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...