qwertyqwerty
qwertyqwerty

Reputation: 235

Intellij Debug Docker container keeps giving me IO Exception Handshake Failed

I am trying to setup a remote debugger in Intellij v2020.1, I keep getting the error below:

Unable to open debugger port (localhost:5005): java.io.IOException "handshake failed - connection prematurally closed"

In my docker compose file I have mounted port 5005 to 5005

In my docker file i have:

EXPOSE 5005

ENTRYPOINT ["/bin/bash", "runme.sh"]

and in my shell script I have:

/opt/java/openjdk/bin/java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -jar mine.jar

When I do a docker ps, i can see the below:

0.0.0.0:5005->5005/tcp, 0.0.0.0:8111->8111/tcp

In IntelliJ I setup the remote debugger from port 5005 to contaier port 5005, added in the module claspath and in the before launch step, added in my compose file.

The service starts up fine, but jut cant connect to the debugger, any ideas?

Upvotes: 9

Views: 12320

Answers (1)

radrocket81
radrocket81

Reputation: 329

Placing this line in my Dockerfile solved it for me:

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

The critical part here, being the "address=*:5005" and not simply "address=5005". Apparently some security changes since Java 9 requires the *: before the port.

EDIT: I see you're on Java 8. But perhaps adding -XDebug to the options as well, could do the trick:

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

Upvotes: 18

Related Questions