Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't remotely debug on Java 9 Tomcat 9 in docker container

I have a Docker container based on opendjdk:8-slim with installed Tomcat 9 and I am debugging apps deployed there from my IDE (IntelliJ) - the IDE runs on Docker host. I run the Tomcat with the following configuration

CATALINA_OPTS="-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.port=49520 \
-Dcom.sun.management.jmxremote.rmi.port=49520 \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.local.only=false \
-Djava.rmi.server.hostname=10.0.75.1 \
-agentlib:jdwp=transport=dt_socket,address=49540,suspend=n,server=y"

Everything works great - I can attach the IDE to the container. Also the following command works (executed from docker host) - it can connect to the process in the container (the port 49540 in the container is mapped to the port 49540 on the host):

docker-host$ telnet localhost 49540

Now I want to upgrade to Java 9. I changed the base image from openjdk:8-slim to openjdk:9-slim and I can't connect to the debugger port from the docker host. Also from IDE, I got SocketTimeoutException: Connection reset. However, from inside the container I am able to connect to the debugger via telnet.

I tried several images of Java 9 from openjdk repository and also from other repos, for example adenix/java, but unfortunately with the same result.

like image 817
fxmasa Avatar asked Nov 07 '17 22:11

fxmasa


1 Answers

Finally I found a way how to make it work using information in the comment provided by Alan Bateman.

Instead of setting debug settings in CATALINA_OPTS (which worked with JDK 8 without problems), I set JPDA_OPTS="-agentlib:jdwp=transport=dt_socket,address=*:4954‌​0,server=y,suspend=n‌​" and run Tomcat with catalina.sh jpda run. The concrete IP address (for instance address=192.168.16.1:49540) still doesn't work for me, although the IP address is reachable from within the container.

like image 135
fxmasa Avatar answered Oct 25 '22 00:10

fxmasa