remote debug本地docker container
background: jdk11/idea2022/docker desktop v20.10.8
Firstly, deploy local java project into local docker machine. Please refer to deploy java project into docker container locally.
At this moment, I assume you have local development env and corresponding runnable docker container.
1. create a remote jave debuger.
Now we have a debug client. Please copy the content of argument and choose local debug source.
参数说明:
# -Xdebug:通知JVM工作在debug模式下;
# -Xnoagent 禁用默认sun.tools.debug调试器。
# -Djava.compiler=NONE 禁止 JIT 编译器的加载。
# -Xrunjdwp:通知JVM使用(java debug wire protocol)来运行调试环境;加载JDWP的JPDA参考执行实例
# transport:监听Socket端口连接方式(也可以dt_shmem共享内存方式,但限于windows机器,并且服务提供端和调试端只能位于同一台机);
# server:server=y表示当前是调试服务端,=n表示当前是调试客户端
# suspend:suspend=n表示启动时不中断,一般用于设置主动连接;suspend=y表示启动时就进入调试模式,一般用于被动连接

2. Config the application that will be deployed into docker container.
There are two ways. You can choose anyone.
Method one: Update Dockerfile.
The content of JAVA_TOOL_OPTIONS is the content that is copied in the previous step.(Attention: the port 5005 can' t be occupied otherwise you need to set a new one. 8081 is the port of the application.)
FROM openjdk:11
MAINTAINER ***
ADD build/libs/grand-world-flight-service-latest-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-jar","app.jar"]
ENV JAVA_TOOL_OPTIONS -Xdebug-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005
EXPOSE 5005 8081
Method Two: Edit configuration of application in idea.
expose ports.
Add environment variables.
JAVA_TOOL_OPTIONS = -Xdebug -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005
