gpt4 book ai didi

docker Jboss/wildfly : How to add datasources and MySQL connector

转载 作者:行者123 更新时间:2023-12-02 18:16:39 25 4
gpt4 key购买 nike

我正在学习 Docker,这对我来说是全新的。我已经能够创建一个 jboss/wildfly 图像,然后我能够使用这个 Dockerfile 在我的应用程序中启动 jboss:

FROM jboss/wildfly

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

ADD mywebapp-web/target/mywebapp-1.0.war /opt/jboss/wildfly/standalone/deployments/mywebapp-1.0.war

现在我想通过向独立和 mysql 连接器添加数据源来添加对 MySQL 数据库的支持。为此,我正在关注这个例子:

https://github.com/arun-gupta/docker-images/tree/master/wildfly-mysql-javaee7

以下是我的 dockerfile 和我的 execute.sh 脚本

docker 文件:

FROM jboss/wildfly:latest

ADD customization /opt/jboss/wildfly/customization/

CMD ["/opt/jboss/wildfly/customization/execute.sh"]

执行脚本代码:

#!/bin/bash

# Usage: execute.sh [WildFly mode] [configuration file]
#
# The default mode is 'standalone' and default configuration is based on the
# mode. It can be 'standalone.xml' or 'domain.xml'.

echo "=> Executing Customization script"

JBOSS_HOME=/opt/jboss/wildfly
JBOSS_CLI=$JBOSS_HOME/bin/jboss-cli.sh
JBOSS_MODE=${1:-"standalone"}
JBOSS_CONFIG=${2:-"$JBOSS_MODE.xml"}

function wait_for_server() {
until `$JBOSS_CLI -c ":read-attribute(name=server-state)" 2> /dev/null | grep -q running`; do
sleep 1
done
}

echo "=> Starting WildFly server"

echo "JBOSS_HOME : " $JBOSS_HOME
echo "JBOSS_CLI : " $JBOSS_CLI
echo "JBOSS_MODE : " $JBOSS_MODE
echo "JBOSS_CONFIG: " $JBOSS_CONFIG

echo $JBOSS_HOME/bin/$JBOSS_MODE.sh -b 0.0.0.0 -c $JBOSS_CONFIG &
$JBOSS_HOME/bin/$JBOSS_MODE.sh -b 0.0.0.0 -c $JBOSS_CONFIG &

echo "=> Waiting for the server to boot"
wait_for_server

echo "=> Executing the commands"
$JBOSS_CLI -c --file=`dirname "$0"`/commands.cli

# Add MySQL module
module add --name=com.mysql --resources=/opt/jboss/wildfly/customization/mysql-connector-java-5.1.39-bin.jar --dependencies=javax.api,javax.transaction.api

# Add MySQL driver
/subsystem=datasources/jdbc-driver=mysql:add(driver-name=mysql,driver-module-name=com.mysql,driver-xa-datasource-class-name=com.mysql.jdbc.jdbc2.optional.MysqlXADataSource)

# Deploy the WAR
#cp /opt/jboss/wildfly/customization/leadservice-1.0.war $JBOSS_HOME/$JBOSS_MODE/deployments/leadservice-1.0.war

echo "=> Shutting down WildFly"
if [ "$JBOSS_MODE" = "standalone" ]; then
$JBOSS_CLI -c ":shutdown"
else
$JBOSS_CLI -c "/host=*:shutdown"
fi

echo "=> Restarting WildFly"
$JBOSS_HOME/bin/$JBOSS_MODE.sh -b 0.0.0.0 -c $JBOSS_CONFIG

但是当我运行图像时出现错误,提示找不到文件或目录:

建筑形象

$ docker build -t mpssantos/leadservice:latest .
Sending build context to Docker daemon 19.37 MB

Step 1 : FROM jboss/wildfly:latest
---> b8279b641e82

Step 2 : ADD customization /opt/jboss/wildfly/customization/
---> aea03d4f2819

Removing intermediate container 0920e2cd97fd

Step 3 : CMD /opt/jboss/wildfly/customization/execute.sh
---> Running in 8a0dbcb01855
---> 10335320b89d

Removing intermediate container 8a0dbcb01855

Successfully built 10335320b89d

SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.

运行图像

$ docker run mpssantos/leadservice
no such file or directory
Error response from daemon: Cannot start container 5d3357ba17afa36e81d8794f2b0cd45cc00dde955b2b2054282c4ef17dd4f265: [8] System error: no such file or directory

有人可以告诉我如何访问文件系统以便检查哪个文件或目录有问题吗?有没有更好的调试方法?

我认为这与脚本第一行提到的 bash 有关,因为没有打印以下回显

非常感谢


我通过 ssh 连接容器来检查里面有什么。

1) ssh 到 docker 机器:docker-machine ssh default2) 使用命令检查容器 ID:docker ps -a3) 使用命令 ssh 到容器:sudo docker exec -i -t 665b4a1e17b6/bin/bash4) 我可以检查“/opt/jboss/wildfly/customization/”目录是否存在预期文件

自定义目录具有以下权限,如下所示:

drwxr-xr-x   2 root    root    4096 Jun 12 23:44 customization
drwxr-xr-x 10 jboss jboss 4096 Jun 14 00:15 standalone

和自定义目录中的文件

drwxr-xr-x  2 root  root    4096 Jun 12 23:44 .
drwxr-xr-x 12 jboss jboss 4096 Jun 14 00:15 ..
-rwxr-xr-x 1 root root 1755 Jun 12 20:06 execute.sh
-rwxr-xr-x 1 root root 989497 May 4 11:11 mysql-connector-java-5.1.39-bin.jar

如果我尝试执行该文件,我会收到此错误

[jboss@d68190e4f0d8 customization]$ ./execute.sh
bash: ./execute.sh: /bin/bash^M: bad interpreter: No such file or directory

这会带来光明吗?

再次感谢您

最佳答案

我发现了问题。 execute.sh 文件与 windows eof 一起使用。我转换到 UNIX 并开始工作。

关于 docker Jboss/wildfly : How to add datasources and MySQL connector,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37778656/

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