无法连接到 Dockerfile 中的 Wildfly [英] Cannot connect to Wildfly in Dockerfile

查看:41
本文介绍了无法连接到 Dockerfile 中的 Wildfly的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个自定义 Dockerfile,其中包含官方 keycloak docker 镜像的扩展.我想更改网络上下文并添加一些自定义提供程序.这是我的 Dockerfile:

I'm creating a custom Dockerfile with extensions for official keycloak docker image. I want to change web-context and add some custom providers. Here's my Dockerfile:

FROM jboss/keycloak:7.0.0

COPY startup-config.cli /opt/jboss/tools/cli/startup-config.cli

RUN /opt/jboss/keycloak/bin/jboss-cli.sh --connect --controller=localhost:9990 --file="/opt/jboss/tools/cli/startup-config.cli"

ENV KEYCLOAK_USER=admin
ENV KEYCLOAK_PASSWORD=admin

和 startup-config.cli 文件:

and startup-config.cli file:

/subsystem=keycloak-server/:write-attribute(name=web-context,value="keycloak/auth")
/subsystem=keycloak-server/:add(name=providers,value="module:module:x.y.z.some-custom-provider")

不幸的是,我收到了这样的错误:

Bu unfortunately I receive such error:

The controller is not available at localhost:9990: java.net.ConnectException: WFLYPRT0053: Could not connect to remote+http://localhost:9990. The connection failed: WFLYPRT0053: Could not connect to remote+http://localhost:9990. The connection failed: Connection refused
The command '/bin/sh -c /opt/jboss/keycloak/bin/jboss-cli.sh --connect --controller=localhost:9990 --file="/opt/jboss/tools/cli/startup-config.cli"' returned a non-zero code: 1

是否是本地主机无效的问题?我应该如何引用管理 API?

Is it a matter of invalid localhost? How should I refer to the management API?

我也尝试过使用 ENTRYPOINT 而不是 RUN,但在容器初始化期间发生了同样的错误.

I also tried with ENTRYPOINT instead of RUN, but the same error occurred during container initialization.

推荐答案

您正在尝试让 Wildfly 在构建时加载您的自定义配置文件.问题是,当 Dockerfile 正在构建时,Wildfly 服务器没有运行.

You are trying to have Wildfly load your custom config file at build-time here. The trouble is, that the Wildfly server is not running while the Dockerfile is building.

Wildfly 实际上已经为您介绍了有关自动加载自定义配置的内容,内置支持您想要做的事情.您只需将配置文件放在图像内的神奇位置"即可.

Wildfly actually already has you covered regarding automatically loading custom config, there is built in support for what you want to do. You simply need to put your config file in a "magic location" inside the image.

你需要把你的配置文件放在这里:

You need to drop your config file here:

/opt/jboss/startup-scripts/

这样你的 Dockerfile 看起来像这样:

So that your Dockerfile looks like this:

FROM jboss/keycloak:7.0.0

COPY startup-config.cli /opt/jboss/startup-scripts/startup-config.cli

ENV KEYCLOAK_USER=admin
ENV KEYCLOAK_PASSWORD=admin

摘自 keycloak 文档:

使用 Dockerfile 添加自定义脚本

可以添加自定义脚本创建自己的 Dockerfile:

A custom script can be added by creating your own Dockerfile:

FROM keycloak 
COPY custom-scripts/ /opt/jboss/startup-scripts/

现在您可以简单地启动映像,keycloak 中的内置功能(实际上是 Wildfly 功能)将在该特定目录中查找配置,然后尝试加载它.

Now you can simply start the image, and the built features in keycloak (Wildfly feature really) will go look for a config in that spedific directory, and then attempt to load it up.

使用最终解决方案编辑评论:

虽然原始答案解决了能够将配置传递到服务器的问题,但脚本内容仍然存在问题.启动容器时收到以下错误:

While the original answer solved the issue with being able to pass configuration to the server at all, an issue remained with the content of the script. The following error was received when starting the container:

=========================================================================
Executing cli script: /opt/jboss/startup-scripts/startup-config.cli
No connection to the controller.
=========================================================================

问题出在 startup-config.cli 脚本中,其中缺少 jboss 命令 embed-server,需要启动与 jboss 的连接实例.还缺少关闭的 stop-embedded-server 命令.有关以这种方式配置 jboss 的更多信息,请参见此处的文档:CHAPTER8. 嵌入服务器进行离线配置

The issue turned out to be in the startup-config.cli script, where the jboss command embed-server was missing, needed to initiate a connection to the jboss instance. Also missing was the closing stop-embedded-server command. More about configuring jboss in this manner in the docs here: CHAPTER 8. EMBEDDING A SERVER FOR OFFLINE CONFIGURATION

最终脚本:

embed-server --std-out=echo
/subsystem=keycloak-server/theme=defaults/:write-attribute(name=cacheThemes,value=false)
/subsystem=keycloak-server/theme=defaults/:write-attribute(name=cacheTemplates,value=false)
stop-embedded-server

这篇关于无法连接到 Dockerfile 中的 Wildfly的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆