dockerfile for wildfly java应用程序

mum43rcc  于 2021-06-23  发布在  Mysql
关注(0)|答案(1)|浏览(396)

我正在尝试为我的wildflyjava应用程序创建一个docker映像。我的应用程序使用jndi创建了一个与数据源的mysql连接。我的orm正在休眠。当我跑的时候

docker build -t mytag-app .

它返回错误:

The command is not available in the current context (e.g. required subsystems or connection to the controller might be unavailable).
The command '/bin/sh -c /opt/jboss/wildfly/bin/jboss-cli.sh --user=admin --password=admin --commands="data-source add --name=source1 --jndi-name=java:jboss/datasources/MySqlDS --driver-name=mysql-connector-java-8.0.11.jar  --connection-url=jdbc:mysql://sihors.com:3306/nynnphsj_wifigate2?serverTimezone=UTC --user-name=nynnphsj_loretto25 --password=dsotmpinkflo --enable=true"' returned a non-zero code: 1

我肯定我的记事本错了,但在哪里?
我运行docker的文件夹有:
平静的战争
mysql-connector-java-8.0.12.jar
dockerfile文件
这是我的文档:

FROM jboss/wildfly

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

ADD restful.war /opt/jboss/wildfly/standalone/deployments/
ADD mysql-connector-java-8.0.12.jar /opt/jboss/wildfly/standalone/deployments/

RUN /opt/jboss/wildfly/bin/jboss-cli.sh --user=admin --password=admin --commands="data-source add --name=source1 --jndi-name=java:jboss/datasources/MySqlDS --driver-name=mysql-connector-java-8.0.11.jar  --connection-url=jdbc:mysql://mydomain.com:3306/mydb2?serverTimezone=UTC --user-name=root --password=root --enable=true"

EXPOSE 8080 9990

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

这是我的pom.xml for java应用程序:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.cosmink</groupId>
<artifactId>restful</artifactId>
<version>1.0</version>
<packaging>war</packaging>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.wildfly.bom</groupId>
            <artifactId>wildfly-javaee7-with-tools</artifactId>
            <version>${version.jboss.bom}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>

    <!-- JAVA EE API -->

    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>8.0</version>
        <scope>provided</scope>
    </dependency>

    <!-- MySQL DRIVER -->

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>8.0.11</version>
    </dependency>

    <!-- Hibernate -->

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.3.1.Final</version>
        <scope>provided</scope>
    </dependency>

    <!-- JJWT -->

    <dependency>
        <groupId>io.jsonwebtoken</groupId>
        <artifactId>jjwt</artifactId>
        <version>${jjwt.version}</version>
    </dependency>

    <!-- jBCrypt -->

    <dependency>
        <groupId>de.svenkubiak</groupId>
        <artifactId>jBCrypt</artifactId>
        <version>${jbcrypt.version}</version>
    </dependency>

    <!-- HttpClient Library -->

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.3.4</version>
    </dependency>

    <!-- Nats Library Client-->

    <dependency>
        <groupId>io.nats</groupId>
        <artifactId>jnats</artifactId>
        <version>2.0.0</version>
    </dependency>

</dependencies>

<build>
    <finalName>restful</finalName>
    <plugins>
        <plugin>
            <groupId>org.wildfly.plugins</groupId>
            <artifactId>wildfly-maven-plugin</artifactId>
            <version>${version.wildfly.maven.plugin}</version>
            <executions>
                <execution>
                    <id>deploy-driver</id>
                    <phase>package</phase>
                    <configuration>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <name>mysql-connector-java-8.0.11.jar</name>
                    </configuration>
                    <goals>
                        <goal>deploy-artifact</goal>
                    </goals>
                </execution>
                <execution>
                    <id>add-datasource</id>
                    <phase>install</phase>
                    <configuration>
                        <force>true</force>
                        <address>subsystem=datasources,data-source=java:jboss/datasources/MySqlDS</address>
                        <resources>
                            <resource>
                                <properties>
                                    <jndi-name>java:jboss/datasources/MySqlDS</jndi-name>
                                    <enable>true</enable>
                                    <connection-url>jdbc:mysql://mydomain.com:3306/db?serverTimezone=UTC</connection-url>
                                    <driver-name>mysql-connector-java-8.0.11.jar</driver-name>
                                    <user-name>root</user-name>
                                    <password>root</password>
                                    <pool-name>people-web</pool-name>
                                    <use-java-context>true</use-java-context>
                                </properties>
                            </resource>
                        </resources>
                    </configuration>
                    <goals>
                        <goal>add-resource</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <add-user>
                    <users>
                        <user>
                            <username>admin</username>
                            <password>admin</password>
                        </user>
                    </users>
                </add-user>
            </configuration>
        </plugin>
    </plugins>
</build>

<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <failOnMissingWebXml>false</failOnMissingWebXml>
    <jjwt.version>0.7.0</jjwt.version>
    <jbcrypt.version>0.4.1</jbcrypt.version>
    <version.jboss.bom>13.0.0.Final</version.jboss.bom>
    <version.wildfly.maven.plugin>1.2.1.Final</version.wildfly.maven.plugin>
</properties>

如何使用mysql数据源连接为wildflyjava应用程序创建docker映像?

zhte4eai

zhte4eai1#

docker build 是基于dockerfile构建容器映像。此时,你的容器没有运行,你的wildfly也没有运行。您的jboss-cli.sh无法工作,因为这是关于与正在运行的wildfly交互的。
为了实现你的目标,你有两个选择 ADD 容器中配置了数据源的配置文件(最可能是standalone.xml)。每当容器基于您的图像启动时,wildfly都会读取并连接它。 ADD 自制入口点.sh;一个bash脚本,它将启动wildfly并运行配置widlfy所需的任何东西。

相关问题