23

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.

Iurii Drozdov
  • 1,685
  • 1
  • 12
  • 23

1 Answers1

57

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

Jorrit Posthuma
  • 685
  • 7
  • 5
  • Thanks, this worked for me, not sure why this isn't the accepted answer. – Mikkel Løkke Jan 22 '18 at 11:40
  • 10
    Didn't work for me. Not sure what I'm doing wrong here. I have specified a debug port on my process (running inside a docker container) and I am exposing the port on my docker-compose. What am I missing? – redwulf Mar 18 '20 at 17:22
  • 1
    You might need to run `docker-compose up --build` to rebuild your image once you've fixed the CMD – Fabian Braun Jul 27 '20 at 17:20
  • if I am using docker-compose.yml file and the service I want to debug uses a port mapping 8084:8080, do I need to change the port 5005 to 8084 in the debug configuration window ? and of course, i need to build the image and run docker-compose up, before I start a debug session, right ? – Ahmed Abdelhak Mar 10 '21 at 21:12