title: Dockerfile for Wildfly Java App
body: <p>I'm trying to create a docker image for my <strong>Wildfly Java app</strong>. My application creates a mysql connection with a DataSource with JNDI. My ORM is <strong>Hibernate</strong>. When I run </p>
  
  <pre><code>docker build -t mytag-app .
  </code></pre>
  
  <p>it returns error:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>I'm sure that my <strong>Dockerfile</strong> <strong>is wrong</strong>, but where?</p>
  
  <p>My folder for running docker has:</p>
  
  <ul>
  <li>restful.war</li>
  <li>mysql-connector-java-8.0.12.jar</li>
  <li>Dockerfile</li>
  </ul>
  
  <p>This is my Dockerfile:</p>
  
  <pre><code>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"]
  </code></pre>
  
  <p>And this is my Pom.xml for java app:</p>
  
  <pre><code>&lt;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"&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;groupId&gt;com.cosmink&lt;/groupId&gt;
  &lt;artifactId&gt;restful&lt;/artifactId&gt;
  &lt;version&gt;1.0&lt;/version&gt;
  &lt;packaging&gt;war&lt;/packaging&gt;
  
  &lt;dependencyManagement&gt;
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.wildfly.bom&lt;/groupId&gt;
              &lt;artifactId&gt;wildfly-javaee7-with-tools&lt;/artifactId&gt;
              &lt;version&gt;${version.jboss.bom}&lt;/version&gt;
              &lt;type&gt;pom&lt;/type&gt;
              &lt;scope&gt;import&lt;/scope&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  &lt;/dependencyManagement&gt;
  
  &lt;dependencies&gt;
  
      &lt;!-- JAVA EE API --&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;javax&lt;/groupId&gt;
          &lt;artifactId&gt;javaee-api&lt;/artifactId&gt;
          &lt;version&gt;8.0&lt;/version&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
  
      &lt;!-- MySQL DRIVER --&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;mysql&lt;/groupId&gt;
          &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
          &lt;version&gt;8.0.11&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- Hibernate --&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
          &lt;version&gt;5.3.1.Final&lt;/version&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
  
      &lt;!-- JJWT --&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;io.jsonwebtoken&lt;/groupId&gt;
          &lt;artifactId&gt;jjwt&lt;/artifactId&gt;
          &lt;version&gt;${jjwt.version}&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- jBCrypt --&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;de.svenkubiak&lt;/groupId&gt;
          &lt;artifactId&gt;jBCrypt&lt;/artifactId&gt;
          &lt;version&gt;${jbcrypt.version}&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- HttpClient Library --&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
          &lt;artifactId&gt;httpclient&lt;/artifactId&gt;
          &lt;version&gt;4.3.4&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- Nats Library Client--&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;io.nats&lt;/groupId&gt;
          &lt;artifactId&gt;jnats&lt;/artifactId&gt;
          &lt;version&gt;2.0.0&lt;/version&gt;
      &lt;/dependency&gt;
  
  
  &lt;/dependencies&gt;
  
  &lt;build&gt;
      &lt;finalName&gt;restful&lt;/finalName&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.wildfly.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;wildfly-maven-plugin&lt;/artifactId&gt;
              &lt;version&gt;${version.wildfly.maven.plugin}&lt;/version&gt;
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;id&gt;deploy-driver&lt;/id&gt;
                      &lt;phase&gt;package&lt;/phase&gt;
                      &lt;configuration&gt;
                          &lt;groupId&gt;mysql&lt;/groupId&gt;
                          &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
                          &lt;name&gt;mysql-connector-java-8.0.11.jar&lt;/name&gt;
                      &lt;/configuration&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;deploy-artifact&lt;/goal&gt;
                      &lt;/goals&gt;
                  &lt;/execution&gt;
                  &lt;execution&gt;
                      &lt;id&gt;add-datasource&lt;/id&gt;
                      &lt;phase&gt;install&lt;/phase&gt;
                      &lt;configuration&gt;
                          &lt;force&gt;true&lt;/force&gt;
                          &lt;address&gt;subsystem=datasources,data-source=java:jboss/datasources/MySqlDS&lt;/address&gt;
                          &lt;resources&gt;
                              &lt;resource&gt;
                                  &lt;properties&gt;
                                      &lt;jndi-name&gt;java:jboss/datasources/MySqlDS&lt;/jndi-name&gt;
                                      &lt;enable&gt;true&lt;/enable&gt;
                                      &lt;connection-url&gt;jdbc:mysql://mydomain.com:3306/db?serverTimezone=UTC&lt;/connection-url&gt;
                                      &lt;driver-name&gt;mysql-connector-java-8.0.11.jar&lt;/driver-name&gt;
                                      &lt;user-name&gt;root&lt;/user-name&gt;
                                      &lt;password&gt;root&lt;/password&gt;
                                      &lt;pool-name&gt;people-web&lt;/pool-name&gt;
                                      &lt;use-java-context&gt;true&lt;/use-java-context&gt;
                                  &lt;/properties&gt;
                              &lt;/resource&gt;
                          &lt;/resources&gt;
                      &lt;/configuration&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;add-resource&lt;/goal&gt;
                      &lt;/goals&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
              &lt;configuration&gt;
                  &lt;add-user&gt;
                      &lt;users&gt;
                          &lt;user&gt;
                              &lt;username&gt;admin&lt;/username&gt;
                              &lt;password&gt;admin&lt;/password&gt;
                          &lt;/user&gt;
                      &lt;/users&gt;
                  &lt;/add-user&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
  &lt;/build&gt;
  
  &lt;properties&gt;
      &lt;maven.compiler.source&gt;1.8&lt;/maven.compiler.source&gt;
      &lt;maven.compiler.target&gt;1.8&lt;/maven.compiler.target&gt;
      &lt;failOnMissingWebXml&gt;false&lt;/failOnMissingWebXml&gt;
      &lt;jjwt.version&gt;0.7.0&lt;/jjwt.version&gt;
      &lt;jbcrypt.version&gt;0.4.1&lt;/jbcrypt.version&gt;
      &lt;version.jboss.bom&gt;13.0.0.Final&lt;/version.jboss.bom&gt;
      &lt;version.wildfly.maven.plugin&gt;1.2.1.Final&lt;/version.wildfly.maven.plugin&gt;
  &lt;/properties&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>How to create a docker image for wildfly java app with mysql datasource connection?</strong></p>