How to debug an application running in Docker with IntelliJ?

有些话、适合烂在心里 提交于 2019-12-03 10:53:58

问题


I have a Jetty application running in docker. I would like to debug this application using my local IntelliJ. I am on v 14.1, so I have installed the Docker Integration plugin.

Under Clouds, I am using the default values that showed up when I click on the '+'. IntelliJ docs say this should be OK. Here the

API URL: http://127.0.0.1:2376
Certificates folder: <empty>

I'm not sure what these are used for, so I dont know if these values are right.

Under Run/Debug configurations, I am using Docker Deployment, and the following values:

Deployment: Docker Image
Image ID: The docker image ID 
Container name: The name of the container

When I try to run this, I get javax.ws.rs.ProcessingException: org.apache.http.conn.HttpHostConnectException: Connect to http://127.0.0.1:2376 [/127.0.0.1] failed: Connection refused

Obviously the API URL value I am using is incorrect. Any suggestions on what that value should be?

My debugging options are:

 -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=n -Djava.compiler=NONE

回答1:


Sheesh Never mind. I didnt really need the Docker Integration plugin. Seems like that is more for deployment and management of Docker directly through Intellij than for debugging.

To debug my jetty app running inside my docker container, I simply remote debugged:

Run | Edit configurations | + | Remote

The command line args were already OK since I used the default remote debugging options. I only needed to change the Host settings. Here I used the hostname I had set within the docker container




回答2:


In Java 8 the JDK supports a JAVA_TOOL_OPTIONS environment variable so to enable the debugger for any Java application you can add the following parameters to your docker run command:

-p 8000:8000 -e "JAVA_TOOL_OPTIONS=\"-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n\""

Then start a remote debug session connecting to localhost:8000.




回答3:


If anybody wants to do development on windows machine, and run/debug app at same time on a remote docker, you can check my intellij plugin here: https://bojanv55.wordpress.com/2018/08/03/intellij-idea-remote-debug-of-java-code-inside-docker-container/



来源:https://stackoverflow.com/questions/34157900/how-to-debug-an-application-running-in-docker-with-intellij

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!