In this tutorial I will show how to set up a MySQL docker container for use by a separate Docker container running Wildfly Application Server. See part 1 of the tutorial on how to set up Docker and create a Wildfly container.

This will define a stack consisting of a MySQL container „db“ based on „j-lawyer-mysql-server“ and a Wildfly container „server“ based on „j-lawyer-server“. Port 8000 will be exposed for the Wildfly containers port 8080.

Launch the stack

sudo docker-compose -f j-lawyer-server-stack.yaml up

If you fire up http://localhost:8000 you will see the Wildfly welcome page. When executing a

Now, let’s verify the Wildfly container has access to the MySQL container, by starting a Bash inside the Wildfly container in your stack. Note the container name, taken from the output of the last command:

sudo docker exec -it j-lawyer-server-stack_server_1 bash

The host name of the MySQL container matches the MySQL containers logical name in your stack definition (.yaml), in our case „db“. Let’s see if we can ping this:

ping db

You will see this works. Your MySQL container can be reached from within your Wildfly container.

Next Steps

In this tutorial, parts 1 and 2, we have installed Docker, set up a Wildfly image as well as a MySQL image, and defined a stack combining the two. Everything else is pretty straight forward, e.g.

Add a datasource configuration for Wildfly in your Wildfly image, pointing to MySQL on the host „db“.

Add RUN entries in your MySQL image to create a database and some schema objects