带Postgres的Keycloak无法在运行时启动

时间:2019-06-06 14:09:28

标签: postgresql docker jboss keycloak

我正在尝试使用docker在本地运行Keycloak w / Postgres

$ docker network create keycloak-network
$ docker volume create pgdata
$ docker run -d -p 127.0.0.1:5432:5432 --name postgres --net keycloak-network -e POSTGRES_DB=keycloak -e POSTGRES_USER=keycloak -e POSTGRES_PASSWORD=password -v pgdata:/var/lib/postgresql/data postgres
$ docker run --name keycloak --net keycloak-network -p 8080:8080 -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin jboss/keycloak

构建Keycloak时失败。

  

13:51:13,388错误[org.jboss.msc.service.fail](ServerService线程   池-61)MSC000001:无法启动服务   jboss.deployment.unit。“ keycloak-server.war” .undertow-deployment:   服务中的org.jboss.msc.service.StartException   jboss.deployment.unit。“ keycloak-server.war” .undertow-deployment:   java.lang.RuntimeException:RESTEASY003325:无法构造公共   org.keycloak.services.resources.KeycloakApplication(javax.servlet.ServletContext,org.jboss.resteasy.core.Dispatcher)     在   org.wildfly.extension.undertow.deployment.UndertowDeploymentService $ 1.run(UndertowDeploymentService.java:81)     在   java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:511)     在java.util.concurrent.FutureTask.run(FutureTask.java:266)在   org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)     在   org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1982)     在   org.jboss.threads.EnhancedQueueExecutor $ ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)     在   org.jboss.threads.EnhancedQueueExecutor $ ThreadBody.run(EnhancedQueueExecutor.java:1377)     在java.lang.Thread.run(Thread.java:748)在   org.jboss.threads.JBossThread.run(JBossThread.java:485)由以下原因引起:   java.lang.RuntimeException:RESTEASY003325:无法构造公共   org.keycloak.services.resources.KeycloakApplication(javax.servlet.ServletContext,org.jboss.resteasy.core.Dispatcher)     在   org.jboss.resteasy.core.ConstructorInjectorImpl.construct(ConstructorInjectorImpl.java:164)     在   org.jboss.resteasy.spi.ResteasyProviderFactory.createProviderInstance(ResteasyProviderFactory.java:2750)     在   org.jboss.resteasy.spi.ResteasyDeployment.createApplication(ResteasyDeployment.java:364)     在   org.jboss.resteasy.spi.ResteasyDeployment.startInternal(ResteasyDeployment.java:277)     在   org.jboss.resteasy.spi.ResteasyDeployment.start(ResteasyDeployment.java:89)     在   org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.init(ServletContainerDispatcher.java:119)     在   org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.init(HttpServletDispatcher.java:36)     在   io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:117)     在   org.wildfly.extension.undertow.security.RunAsLifecycleInterceptor.init(RunAsLifecycleInterceptor.java:78)     在   io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:103)     在   io.undertow.servlet.core.ManagedServlet $ DefaultInstanceStrategy.start(ManagedServlet.java:303)     在   io.undertow.servlet.core.ManagedServlet.createServlet(ManagedServlet.java:143)     在   io.undertow.servlet.core.DeploymentManagerImpl $ 2.call(DeploymentManagerImpl.java:583)     在   io.undertow.servlet.core.DeploymentManagerImpl $ 2.call(DeploymentManagerImpl.java:554)     在   io.undertow.servlet.core.ServletRequestContextThreadSetupAction $ 1.call(ServletRequestContextThreadSetupAction.java:42)     在   io.undertow.servlet.core.ContextClassLoaderSetupAction $ 1.call(ContextClassLoaderSetupAction.java:43)     在   org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda $ create $ 0(SecurityContextThreadSetupAction.java:105)     在   org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService $ UndertowThreadSetupAction.lambda $ create $ 0(UndertowDeploymentInfoService.java:1502)     在   org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService $ UndertowThreadSetupAction.lambda $ create $ 0(UndertowDeploymentInfoService.java:1502)     在   org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService $ UndertowThreadSetupAction.lambda $ create $ 0(UndertowDeploymentInfoService.java:1502)     在   org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService $ UndertowThreadSetupAction.lambda $ create $ 0(UndertowDeploymentInfoService.java:1502)     在   io.undertow.servlet.core.DeploymentManagerImpl.start(DeploymentManagerImpl.java:596)     在   org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:97)     在   org.wildfly.extension.undertow.deployment.UndertowDeploymentService $ 1.run(UndertowDeploymentService.java:78)     ... 8更多原因:java.lang.RuntimeException:无法连接   到数据库   org.keycloak.connections.jpa.DefaultJpaConnectionProviderFactory.getConnection(DefaultJpaConnectionProviderFactory.java:382)     在   org.keycloak.connections.jpa.updater.liquibase.lock.LiquibaseDBLockProvider.lazyInit(LiquibaseDBLockProvider.java:65)     在   org.keycloak.connections.jpa.updater.liquibase.lock.LiquibaseDBLockProvider.lambda $ waitForLock $ 0(LiquibaseDBLockProvider.java:97)     在   org.keycloak.models.utils.KeycloakModelUtils.suspendJtaTransaction(KeycloakModelUtils.java:678)     在   org.keycloak.connections.jpa.updater.liquibase.lock.LiquibaseDBLockProvider.waitForLock(LiquibaseDBLockProvider.java:95)     在   org.keycloak.services.resources.KeycloakApplication $ 1.run(KeycloakApplication.java:144)     在   org.keycloak.models.utils.KeycloakModelUtils.runJobInTransaction(KeycloakModelUtils.java:227)     在   org.keycloak.services.resources.KeycloakApplication。(KeycloakApplication.java:137)     在sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native   方法)   sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)     在   sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)     在java.lang.reflect.Constructor.newInstance(Constructor.java:423)     在   org.jboss.resteasy.core.ConstructorInjectorImpl.construct(ConstructorInjectorImpl.java:152)     ... 31更多原因:javax.naming.NameNotFoundException:   数据源/ KeycloakDS-服务   jboss.naming.context.java.jboss.datasources.KeycloakDS位于   org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:106)     在org.jboss.as.naming.NamingContext.lookup(NamingContext.java:207)     在org.jboss.as.naming.NamingContext.lookup(NamingContext.java:184)     在   org.jboss.as.naming.InitialContext $ DefaultInitialContext.lookup(InitialContext.java:239)     在org.jboss.as.naming.NamingContext.lookup(NamingContext.java:193)     在org.jboss.as.naming.NamingContext.lookup(NamingContext.java:189)     在javax.naming.InitialContext.lookup(InitialContext.java:417)处   javax.naming.InitialContext.lookup(InitialContext.java:417)在   org.keycloak.connections.jpa.DefaultJpaConnectionProviderFactory.getConnection(DefaultJpaConnectionProviderFactory.java:375)     ...还有43

通过默认的Keycloak实例运行h2可以正常工作,因此我只能假定这与挂钩Postgres

有关

1 个答案:

答案 0 :(得分:0)

像keycloak一样无法连接到数据库

Caused by: java.lang.RuntimeException: Failed to connect to database

我发现使用docker-compose启动多个服务更加容易。这是我在本地使用的docker-compose.yml for postgres和keycloak


version: "3"
services:
  keycloak:
    image: jboss/keycloak
    depends_on:
      - postgres
    environment:
      - KEYCLOAK_USER=admin
      - KEYCLOAK_PASSWORD=password
      - KEYCLOAK_HTTP_PORT=8484
      - TEMPLATE_MODE=true
      - DB_VENDOR=POSTGRES
      - DB_ADDR=postgres
    ports:
      - 8484:8484
      - 8485:80
      - 8486:8080
  postgres:
    image: postgres:11.2
    volumes:
      - data-volume3:/var/lib/postgresql/data
    environment:
      - POSTGRES_USER=keycloak
      - POSTGRES_PASSWORD=password
      - POSTGRES_DB=keycloak
    ports:
      - 7654:5432
volumes:
  data-volume3: