linuxdockerdebuggingremote-debuggingjava-17

Error running 'remote_debug': Unable to open debugger port (localhost:4004): java.io.IOException "handshake failed - connection prematurally closed"


I am getting below error while conneting to remote jvm debug port from intelliJIdea. Note: I am using Java 17 in my intellijIdea project and also have docker image with Java 17 Env.

Error:

Error running 'remote_jvm_debug': Unable to open debugger port (localhost:4004): java.io.IOException "handshake failed - connection prematurally closed"

In Dockerfile I am using below environment conf:

ENV JAVA_TOOL_OPTIONS="-Xdebug -agentlib:jdwp=transport=dt_socket,address=*:4004,server=y,suspend=n" 

I also tried below ENV in my Dockerfile, but no luck:

ENV JAVA_TOOL_OPTIONS="-agentlib:jdwp=transport=dt_socket,address=0.0.0.0:4004,server=y,suspend=n"

To establish a tunnel on my remote server on which I run docker container, I use below command:

ssh -f 10.12.91.11 -L 4004:127.0.0.1:4004 -N

In my docker-compose.yml file I have below port and ENV conf:

    ports:
      - "8002:80"
      - "4004:4004"
    environment:
      JVM_ARGS: *jvmflags
      CATALINA_OPTS_EXTRA: *jvmflags

I tried using below ENV in my Dockerfile which is suggested on stackoverflow and other places, but its not working in my case:

ENV JAVA_TOOL_OPTIONS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:4004"


Solution

  • Let me answer my own question, after reading some links available on the internet and after trying couple of configurations, I could able to successfully enable the remote JVM debug on my Java 17 spring boot application running on Docker environment.

    You need to add following env variable under environment configuration in your docker-compose.yml:

    JAVA_OPTS: "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:4003"
    

    And at the same time you will need to comment out any old Java 8 environment variables if they are present in your docker-compose.yml file:

    #JVM_ARGS: *jvmflags
    #CATALINA_OPTS_EXTRA: *jvmflags
    

    Here is official IntellijIdea link for Java 17 Remote JVM Debug configurations details for your reference! Enjoy!😉 😊