gpt4 book ai didi

docker - 如何使用 Dockerfile 在启动 docker 容器上运行 jboss-cli

转载 作者:行者123 更新时间:2023-12-02 17:59:11 31 4
gpt4 key购买 nike

我正在尝试使用 Dockerfile 创建图像 docker 容器。当 docker 容器启动时,我需要使用 jboss-cli 执行一些命令。要执行 jboss-cli,wildfly 服务必须正在运行。

我的 Dockerfile:

FROM jboss/wildfly:latest

USER jboss

RUN /opt/jboss/wildfly/bin/add-user.sh admin admin --silent

CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0"]

我尝试在我的 Dockerfile 中添加一个 jboss-cli 命令
FROM jboss/wildfly:latest

USER jboss

COPY mysql-connector-java-5.1.44.jar /opt/jboss/

RUN /opt/jboss/wildfly/bin/add-user.sh admin admin --silent

USER root
#in this line is needed to change owner file to jboss user use this file
RUN chown jboss.root /opt/jboss/mysql-connector-java-5.1.44.jar
USER jboss

CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0"]
CMD ["/opt/jboss/wildfly/bin/jboss-cli.sh", "-c", "controller=localhost:9990", "--user=admin", "--password=admin", "--command=\"module add --name=com.mysql --resources=/opt/jboss/mysql-connector-java-5.1.44.jar --dependencies=javax.api,javax.transaction.api\""]

当我运行 docker run 命令时:
docker run --name=wildfly-ci -p 8080:8080 -p 9990:9990 wildfly-ci

运行 docker 命令时,我从 jboss-cli 收到此消息错误
Failed to connect to the controller: 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: XNIO000812: Connection closed unexpectedly

我不知道是因为 Wildfly 的服务此时尚未运行,还是因为 Docker Container 的某些行为。

最佳答案

这对我有用:

   RUN /bin/sh -c '$JBOSS_HOME/bin/standalone.sh -c=standalone-full.xml &' && \
sleep 10 && \
cd /tmp && \
$JBOSS_HOME/bin/jboss-cli.sh --connect --command="module add --name=org.postgresql --resources=$JBOSS_HOME/standalone/configuration/postgresql-42.2.5.jar --dependencies=javax.api,javax.transaction.api,javax.servlet.api" && \
$JBOSS_HOME/bin/jboss-cli.sh --connect --command=:shutdown


# User root to modify war owners
USER root

CMD ["/opt/eap/bin/standalone.sh", "-c", "standalone-full.xml", "-b", "0.0.0.0","-bmanagement","0.0.0.0"]

关于docker - 如何使用 Dockerfile 在启动 docker 容器上运行 jboss-cli,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56060964/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com