Remote debugging Java 9 in a docker container from IntelliJ IDEA

匿名 (未验证) 提交于 2019-12-03 02:49:01

问题:

I have a Dockerfile with this content:

FROM openjdk:9  WORKDIR /project  ADD . /project  EXPOSE 5005 

My docker-compose.yml looks like this:

version: "3.2" services:   some-project:     build: .     ports:       - target: 5005         published: 5005         protocol: tcp         mode: host   command: "java '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005' SomeClass" 

When I do docker-composer up I see a message "Listening for transport dt_socket at address: 5005". But when I try to connect with jdb or Idea I get "java.io.IOException: handshake failed - connection prematurally closed".

Everything works fine if I change openjdk:9 to openjdk:8. However, I need Java 9 for my project.

回答1:

From Java 9, the JDWP socket connector accept only local connections by default. See: http://www.oracle.com/technetwork/java/javase/9-notes-3745703.html#JDK-8041435

So, to enable debug connections from outside, specify *:<port> as address:

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



回答2:

This is not an answer just a confirmation. Actually this is almost exactly how we do it:

  • ports: <someport>:5005
  • -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
  • In IDE connect to <someport> with remote debugger.


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