Failed to start keycloak by docker command with mysql in wsl(docker desktop)

37 views
Skip to first unread message

Li Zhang

unread,
Sep 1, 2025, 2:46:33 AM (6 days ago) Sep 1
to Keycloak User
All,
I am new to keycloak. I failed to run keycloak with mysql with docker command.
The command I used:
docker run --privileged=true -d --network host --name keycloak --restart always  -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin quay.io/keycloak/keycloak:26.3.1 start --db mysql --db-password 654321 --db-schema keycloak --db-url 'jdbc:mysql://127.0.0.1:3306/keycloak?serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&connectTimeout=30000' --db-username zhangli --http-port 8089 --http-management-port 8090 --http-enabled true --proxy-headers forwarded --hostname https://172.17.142.82:17040/auth --hostname-backchannel-dynamic true --hostname-debug true --verbose --log-level debug

The Error I got:
2025-08-28 01:49:52,934 DEBUG [io.quarkus.hibernate.orm.runtime.FastBootHibernatePersistenceProvider] (JPA Startup Thread) No PersistenceProvider explicitly requested, assuming Hibernate 2025-08-28 01:49:53,327 DEBUG [io.quarkus.agroal.runtime.DataSources] (JPA Startup Thread) Started datasource <default> connected to jdbc:mysql://127.0.0.1:3306/keycloak?serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&connectTimeout=30000 2025-08-28 01:49:53,403 DEBUG [org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl] (JPA Startup Thread) `hibernate.connection.provider_disables_autocommit` was enabled. This setting should only be enabled when you are certain that the Connections given to Hibernate by the ConnectionProvider have auto-commit disabled. Enabling this setting when the Connections do not have auto-commit disabled will lead to Hibernate executing SQL operations outside of any JDBC/SQL transaction. 2025-08-28 01:49:54,068 WARN [io.agroal.pool] (agroal-11) Datasource '<default>': Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. 2025-08-28 01:49:54,082 WARN [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator] (JPA Startup Thread) HHH000342: Could not obtain connection to query metadata: org.hibernate.exception.JDBCConnectionException: unable to obtain isolated JDBC connection [Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.] [n/a] at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:100) at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:58)

When I use tcpdump to check the possible reason of connection error, I got nothing. So it seems the container didn't even try connect before it declares failure.

please note the same docker command could boot up the container successfully on ubuntu 22.04 running in VMware player.

BR
/Li

Digitaru Miro

unread,
Sep 4, 2025, 2:50:18 AM (3 days ago) Sep 4
to Keycloak User
Hi! If i'm not mistaken you're telling Keycloak inside of Docker that the database is located at "jdbc:mysql://127.0.0.1:3306", but the "127.0.0.1" of the Keycloak container is not the same "127.0.0.1", aka localhost, of your host machine. You might need to use the IP of the host, or something like "host.docker.internal", which is what I use in MacOs, not suer what is the version in Windows. 
Reply all
Reply to author
Forward
0 new messages