3

I have a maven project that contains integration tests and I use the surefire plugin. I can run the tests with

mvn clean package

and that works fine. I can also remote debug the integration tests using intellij. To do so I execute

mvn clean package -Dmaven.surefire.debug

and in Intellij I create a Run/Debug Configuration of type "Remote" setting Host to localhost and Port to 5005. As soon as the console prints

Listening for transport dt_socket at address: 5005

I start the remote debugging in intellij and everything works fine.

The thing is I want to execute the integration tests inside a docker container and especially also debug them inside the container. I have created a docker image with java, maven and all the other stuff my application needs. In the Entrypoint I start my application and then I start the integration tests with

mvn clean package -Dmaven.surefire.debug

inside the docker container. I run the docker container with the option

-p 5005:5005

to open that port for remote debugging. When running the container, at some point I can see the console output

Listening for transport dt_socket at address: 5005

But when I start the remote debugger in intellij, it won't connect but instead gives me the following error message

Error running '...':
Unable to open debugger port (localhost:5005): java.net.SocketException "Connection reset"

and if I try again to start the debugger i get the error message

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

But the port should be open, because executing

nc -zv localhost 5005

in the host (netcat) results in

Connection to localhost 5005 port [tcp/*] succeeded!

But if execute the same netcat command inside the docker container it results in

localhost [...] 5005 (?) : Connection refused

Can anybody tell me what I am doing wrong? I don't insist on debugging with intellij, but being able to debug the tests inside the docker container somehow would be amazing.

Tzedaqah
  • 91
  • 5
  • You need to launch the java in debug mode on the target host - that means inside docker container host. And make sure this host:port is accessible from the host where IDE is run from where you launch remote debug configuration. – Andrey Jan 23 '20 at 08:07

1 Answers1

6

The answer actually can be found here: Remote debugging Java 9 in a docker container from IntelliJ IDEA

In my case this means, that running the tests with

mvn clean package -Dmaven.surefire.debug="-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=*:5005"

solves the problem

Tzedaqah
  • 91
  • 5