24 July 2016

Running Docker Wildfly/JBoss Application Server in Debug mode via Eclipse

I have recently built the whole Development Environment of Java Enterprise Edition (J2EE) project on multiple Docker containers. It has saved the hassle of setting up a dev env for new developers. All it takes to setup the environment is to clone our github repositories and run the Docker images.

I will explain the setup in a future post.

Build Wildfly Docker Image with Debugging Enabled


So basically in order to run the Wildfly in debug mode, we need to add --debug flag to the Wildfly standalone.sh startup script.

Also we need to expose port 8787 in our image as it's the default port for Wildfly JVM debug mode.

1. Create or change your Wildfly Dockerfile as follows:
$ cat Dockerfile
FROM jboss/wildfly:10.0.0.Final
EXPOSE 8787 
CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0", "--debug"]
2. Build and tag the image:
$ docker build -t wildfly-debug .
3. Run the image either via  docker run:
$ docker run -it -p 8080:8080 -p 8787:8787 --name wfdebug wildfly-debug 
or via docker-compose:
$ cat docker-compose.yml
version: '2'
services:
  wfdebug:
    image: wildfly-debug
    ports:
      - "8080:8080"
      - "8787:8787"
 
$ docker-compose up wfdebug

Eclipse Settings:

In the Eclipse, go to following path:

Window -> Perspective -> Open Perspective -> Debug

Now click on the arrow key next to the Debug button and choose "Debug Configurations"

On the left sidebar, choose "Remote Java Application", right click and New. 

- Give it a Name
- In the Connect tab, left the Project blank
- Choose the Connection Type as "Standard (Socket Attach)"
- Connection Properties: Host: "localhost", Port: "8787"
- In the Source tab, click Add, choose Java Project, and choose the project(s) you want to debug

Apply the changes, and click on Debug!

Boom! It should now connect to the remote Wildfly server running on docker in Debug mode.

I have faced below error several times whenever I don't properly follow the mentioned steps:
"Failed to connect to remote VM. Connection refused."