java - 由于部署目录无法访问,Keycloak 启动时扫描失败 :/opt/jboss/keycloak/standalone/deployments

标签 java docker jboss keycloak

将我的 Keycloak 部署到 Docker 群时,我们在堆栈跟踪中收到以下警告和错误:

我们正在尝试将 keycloak SPI 部署到给定的卷中。这有效,但 keycloak 无法写入/读取该卷。

10:13:05,350 INFO  [org.jboss.modules] (main) JBoss Modules version 1.10.2.Final

10:13:06,057 INFO  [org.jboss.msc] (main) JBoss MSC version 1.4.12.Final

10:13:06,069 INFO  [org.jboss.threads] (main) JBoss Threads version 2.4.0.Final

10:13:06,220 INFO  [org.jboss.as] (MSC service thread 1-2) WFLYSRV0049: Keycloak 12.0.1 (WildFly Core 13.0.3.Final) starting

10:13:06,392 INFO  [org.jboss.vfs] (MSC service thread 1-4) VFS000002: Failed to clean existing content for temp file provider of type temp. Enable DEBUG level log to find what caused this

10:13:07,466 INFO  [org.wildfly.security] (ServerService Thread Pool -- 22) ELY00001: WildFly Elytron version 1.13.1.Final

10:13:08,587 INFO  [org.jboss.as.controller.management-deprecated] (Controller Boot Thread) WFLYCTL0028: Attribute 'security-realm' in the resource at address '/core-service=management/management-interface=http-interface' is deprecated, and may be removed in a future version. See the attribute description in the output of the read-resource-description operation to learn more about the deprecation.

10:13:08,653 WARN  [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) WFLYDS0039: /opt/jboss/keycloak/standalone/deployments is not writable

10:13:08,675 ERROR [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) WFLYDS0042: Boot-time scan failed due to inaccessible deployment directory: /opt/jboss/keycloak/standalone/deployments

10:13:08,690 INFO  [org.jboss.as.controller.management-deprecated] (ServerService Thread Pool -- 3) WFLYCTL0028: Attribute 'security-realm' in the resource at address '/subsystem=undertow/server=default-server/https-listener=https' is deprecated, and may be removed in a future version. See the attribute description in the output of the read-resource-description operation to learn more about the deprecation.

10:13:08,861 INFO  [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0039: Creating http management service using socket-binding (management-http)

错误 WFLYDS0039 和 WFLYDS0042 是问题所在。 我们将部署文件夹安装到服务器上的 Docker 卷,路径为:/srv/keycloak_providers 部署 SPI 时,我可以看到可以在服务器上的上述路径中找到 .JAR 文件。

这是 keycloak docker-compose 文件:

version: "3.7"
services:
  db:
    image: mariadb
    volumes:
      - keycloak_db:/var/lib/mysql
    environment:
      MYSQL_DATABASE: keycloak
    networks:
      db:
        aliases:
          - mariadb

  keycloak:
    image: jboss/keycloak:12.0.1
    environment:
      - DB_ADDR=mariadb
      - DB_PORT=3306
      - DB_DATABASE=keycloak
      - DB_VENDOR=mariadb
      - PROXY_ADDRESS_FORWARDING=true
    networks:
      - public
      - db
    volumes:
      - keycloak_themes:/opt/jboss/keycloak/themes
      - keycloak_providers:/opt/jboss/keycloak/standalone/deployments/
networks:
  db:
    driver: overlay
  public:
    external: true

volumes:
  keycloak_db:
    driver: local-persist
    driver_opts:
      mountpoint: /srv/keycloak_db
  keycloak_themes:
    driver: local-persist
    driver_opts:
      mountpoint: /srv/keycloak_themes
  keycloak_providers:
    driver: local-persist
    driver_opts:
      mountpoint: /srv/keycloak_providers

最佳答案

Keycloak 服务器以 jboss 用户身份运行,其 uid/gid 设置为 1000。确保用户 ID 1000 具有该源文件夹 /srv/keycloak_providers 的读/写权限。最简单的解决方案是从主机操作系统 CLI 执行 chmod -R 777/srv/keycloak_providers。但您可能需要更安全的权限配置 - 只需记住 uid 1000 必须具有读/写访问权限 + 最终还有来自主机操作系统的一些用户。

当然,如果 Docker 守护进程/Keycloak 容器配置了 uid 重新映射,情况可能会更复杂 - 现场会有另一个 uid。

关于java - 由于部署目录无法访问,Keycloak 启动时扫描失败 :/opt/jboss/keycloak/standalone/deployments,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65482455/

相关文章:

java - "synchronized"以外的 Java 类中的 getter 的线程安全习语

docker - 如何在Alpine headless chrome中使用中文?

docker - 如何使用 Grafana Docker 连接 MySQL 到本地 MySQL 服务器

jboss - 将Drools与JBossESB集成

java - JBoss 标准输出未显示在 Eclipse 控制台 View 中

java - Android 游戏 API : Leaderboard - Get specific player score?

java - CDI——处理错误

java - Java应用程序拒绝将输出显示为 float 。尝试过强制转换,乘以1.0,加上0.0,没有任何作用

javascript - 无法连接到 dockerized postgresql 服务器

jboss - 在 JNDI Jboss Seam 中找不到 EntityManagerFactory