• +94712452807
  • pubudu2013101@gmail.com
  • No 39, 2nd Lane, Dikhenapura, Horana
Docker
Docker: How to remote debug tomcat docker container

Docker: How to remote debug tomcat docker container

This is very simple task. I will use IntelliJ idea as my IDE. If you are reading this article you should work with docker and you might familiar with that. Because of that i won’t explain the part of creating a docker container.

First thing you need to do it to add following environment variables.

-e JPDA_ADDRESS=8000 \
-e JPDA_TRANSPORT=dt_socket 

Then you need to run tomcat container with jpda parameter. So full docker run script can be like below

docker run -it --rm \
  -e JPDA_ADDRESS=8001 \
  -e JPDA_TRANSPORT=dt_socket \
  -p 8080:8080 \
  -p 8001:8001 \
  tomcat:8.0 \
  /usr/local/tomcat/bin/catalina.sh jpda run

Now your tomcat container is started in debug mode. Now you need to open the application in IntelliJ which is running on the container and set a debug point to somewhere.

Open the run/debug configuration window. Then click + and select remote. Now add the host and JPDA port and click apply. Finally click the debug icon then you will be able to debug you application.

Sometimes you will get this error.

Debug: Unable to open debugger port (127.0.0.1:8001): java.net.ConnectException “Connection refused”

This happens because your jpda port is not exposed to outside of the container or else you didn’t run docker container with jpda run.

Hope you enjoyed today lesson. Thank you for reading this. Don’t forget to put a comment if you have any issue

Leave a Reply

Your email address will not be published.