Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug port not exposed when using jvmArguments in Dockerfile CMD #20110

Closed
1 task done
nlecaros opened this issue May 27, 2024 · 0 comments · Fixed by #20335
Closed
1 task done

Debug port not exposed when using jvmArguments in Dockerfile CMD #20110

nlecaros opened this issue May 27, 2024 · 0 comments · Fixed by #20335
Assignees
Labels
area/get-started Relates to get started and onboarding docs

Comments

@nlecaros
Copy link

Is this a docs issue?

  • My issue is about the documentation content or website

Type of issue

Information is incorrect

Description

Using JDK 17 and following the instructions in the section Dockerfile for development, this statement in Dockerfile does not cause the JVM to listen on port 8000:

CMD [ "java", "-Dspring.profiles.active=postgres", "-Dspring-boot.run.jvmArguments='-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8000'", "org.springframework.boot.loader.launch.JarLauncher"

While trying to attach to that port within the container, I get a "connection refused.":

docker compose up --build
...
docker exec -ti spring-petclinic-server-1 bash
root@95632c87fcf7:/build# jdb -attach localhost:8000
java.net.ConnectException: Connection refused
	at java.base/sun.nio.ch.Net.connect0(Native Method)
	at java.base/sun.nio.ch.Net.connect(Net.java:579)
	at java.base/sun.nio.ch.Net.connect(Net.java:568)
	at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:593)
	at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)
	at java.base/java.net.Socket.connect(Socket.java:633)
	at jdk.jdi/com.sun.tools.jdi.SocketTransportService.attach(SocketTransportService.java:261)
	at jdk.jdi/com.sun.tools.jdi.GenericAttachingConnector.attach(GenericAttachingConnector.java:119)
	at jdk.jdi/com.sun.tools.jdi.SocketAttachingConnector.attach(SocketAttachingConnector.java:83)
	at jdk.jdi/com.sun.tools.example.debug.tty.VMConnection.attachTarget(VMConnection.java:557)
	at jdk.jdi/com.sun.tools.example.debug.tty.VMConnection.open(VMConnection.java:367)
	at jdk.jdi/com.sun.tools.example.debug.tty.Env.init(Env.java:63)
	at jdk.jdi/com.sun.tools.example.debug.tty.TTY.main(TTY.java:1113)

Fatal error:
Unable to attach to target VM.

While trying to attach to that port outside the container, I get "connection prematurally closed":

$ jdb -attach localhost:8000
java.io.IOException: handshake failed - connection prematurally closed
	at jdk.jdi/com.sun.tools.jdi.SocketTransportService.handshake(SocketTransportService.java:139)
	at jdk.jdi/com.sun.tools.jdi.SocketTransportService.attach(SocketTransportService.java:273)
	at jdk.jdi/com.sun.tools.jdi.GenericAttachingConnector.attach(GenericAttachingConnector.java:119)
	at jdk.jdi/com.sun.tools.jdi.SocketAttachingConnector.attach(SocketAttachingConnector.java:83)
	at jdk.jdi/com.sun.tools.example.debug.tty.VMConnection.attachTarget(VMConnection.java:563)
	at jdk.jdi/com.sun.tools.example.debug.tty.VMConnection.open(VMConnection.java:369)
	at jdk.jdi/com.sun.tools.example.debug.tty.Env.init(Env.java:63)
	at jdk.jdi/com.sun.tools.example.debug.tty.TTY.main(TTY.java:1176)

Fatal error:
Unable to attach to target VM.

The following change to Dockerfile works:

ENV JAVA_TOOL_OPTIONS -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8000
CMD [ "java", "-Dspring.profiles.active=postgres", "org.springframework.boot.loader.launch.JarLauncher" ]

Location

https://docs.docker.com/language/java/develop/#dockerfile-for-development

Suggestion

In Dockerfile, instead of:

CMD [ "java", "-Dspring.profiles.active=postgres", "-Dspring-boot.run.jvmArguments='-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8000'", "org.springframework.boot.loader.launch.JarLauncher"

why not replace the above with:

ENV JAVA_TOOL_OPTIONS -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8000
CMD [ "java", "-Dspring.profiles.active=postgres", "org.springframework.boot.loader.launch.JarLauncher" ]
@nlecaros nlecaros added the status/triage Needs triage label May 27, 2024
@craig-osterhout craig-osterhout added the area/get-started Relates to get started and onboarding docs label May 29, 2024
@craig-osterhout craig-osterhout self-assigned this Jun 28, 2024
@craig-osterhout craig-osterhout removed the status/triage Needs triage label Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/get-started Relates to get started and onboarding docs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants