Start Container, stock tomcat 8.5 in this example
$ docker run \
-eJPDA_OPTS="-agentlib:jdwp=transport=dt_socket,address=5005,server=y,suspend=n" \
-p8080:8080 \
-p5005:5005 \
tomcat:8.5-jdk8 \
catalina.sh jpda run
In IntelliJ, add a launch configuration w/ the following properties:
-
Template:
Remote
-
Debugger Mode:
Attach to remote JVM
-
Host:
localhost
-
Port:
5005
-
Commandline Arguments for remote JVM:
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
Configuration in other debuggers/IDEs is basically the same.
Once the container is running, set a breakpoint / exception breakpoint & start the new launch configuration. The container now suspends once the breakpoint is hit & the stack is visible in your IDE.