Docker Community Forums

Share and learn in the Docker community.

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


(Mpssantos) #1

I am learning Docker which is completely new to me. I already was able to create an jboss/wildfly image, and then i was able to start jboss with my application using this Dockerfile:

FROM jboss/wildfly

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

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

Now i would like to add support for a MySQL Database by adding a datasource to the standalone and the mysql connector. For that i am following this example:

Following is my dockerfile and my script


FROM jboss/wildfly:latest

ADD customization /opt/jboss/wildfly/customization/

CMD ["/opt/jboss/wildfly/customization/"]

execute script code:


# Usage: [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"


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

echo "=> Starting WildFly server"

echo "JBOSS_CLI   : " $JBOSS_CLI

echo $JBOSS_HOME/bin/$ -b -c $JBOSS_CONFIG &

echo "=> Waiting for the server to boot"

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

# 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"
  $JBOSS_CLI -c "/host=*:shutdown"

echo "=> Restarting WildFly"

But I get a error when i run the image complaining that a file or directory is not found:

Building Image

$ 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/
 ---> 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.

Running image

$ 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

Can someone let me know how can i access the filesystem so i can check which file or directory is complaining? Is there a better way to debug this?

I believe that is something related with the bash which is referred on first line of the script because the following echo is not printed

Thank you so much

(Dariusmurawski) #2

You should try to remove this for the debugging purpose. This file is probably missing / somewhere else and docker is not able to find it.

I am not familiar with Wildfly - Is it correct that you first run the standalone command and than add the warfile? And the cp is comment out.

(Mpssantos) #3

Thank you for your response.

Yes i commented out the cp to try to find out what is going wrong. I found something strange:

  1. On my 1st Docker file that is working, with the ADD command i copy the war file and then i start the application server, and it works fine.

  2. I tried to copy to the deployments directory (yes it is stupid but it was just for test purpose) the file and then execute from there because i know that i can copy the war. But when i try to execute the file i get that same message: “no such file or directory”.

Basically i dont know what’s going on when i copy these files.

(Mpssantos) #4

I made it to ssh the container.

  1. ssh to the docker machine: docker-machine ssh default
  2. checked the container id with the command: docker ps -a
  3. ssh to the container with the command: sudo docker exec -i -t 665b4a1e17b6 /bin/bash
  4. i can check that the “/opt/jboss/wildfly/customization/” directory exists with the expected files

The customization dir have the following permissions and is listed like this:

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

and the files inside the customization dir

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
-rwxr-xr-x  1 root  root  989497 May  4 11:11 mysql-connector-java-5.1.39-bin.jar

if i try to execute the file i get this error

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

Does this bring light to anything?

Thank you so much again

(Mpssantos) #5

I found the issue. The file was with windows eof. i converted to UNIX And start to work.

Thank you very much for your attention

(Sejushah17) #6

I tried the exact scripts and steps shared here.

I am getting commands.cli not found