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 working in Docker container #31330

Closed
tmulle opened this issue Feb 21, 2023 · 5 comments · Fixed by #31353
Closed

Debug port not working in Docker container #31330

tmulle opened this issue Feb 21, 2023 · 5 comments · Fixed by #31353
Assignees
Labels
area/container-image kind/bug Something isn't working
Milestone

Comments

@tmulle
Copy link
Contributor

tmulle commented Feb 21, 2023

Describe the bug

This I think is related to #7890

When building my docker image using the Dockerfile.jvm script generated by the code.quarkus.io page and exposing port 5005 like the comments say, I'm unable to connect to the application inside Docker.

I get an error when using NetBeans Remote Debug:
Screenshot 2023-02-21 at 2 58 36 PM

Attaching to localhost:5005
handshake failed - connection prematurally closed

This is how I run my application in docker:

docker run -i --rm -p 5005:5005 -p 8080:8080 -e JAVA_DEBUG=true ....the rest of the line

and this is the log file INSIDE the container. Notice the agent command doesn't have *:5005 or even 0.0.0.0:5005 like the ticket says it should.

Starting the Java application using /opt/jboss/container/java/run/run-java.sh ...
INFO exec  java -Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -XX:+UseParallelGC -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=20 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -XX:+ExitOnOutOfMemoryError -cp "." -jar /deployments/quarkus-run.jar 
Listening for transport dt_socket at address: 5005
__  ____  __  _____   ___  __ ____  ______ 
 --/ __ \/ / / / _ | / _ \/ //_/ / / / __/ 
 -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \   
--\___\_\____/_/ |_/_/|_/_/|_|\____/___/   
2023-02-21 19:39:30,919 WARN  [io.qua.config] (main) Unrecognized configuration key "quarkus.keycloak.devservices.enabled" was provided; it will be ignored; verify that the dependency extension for this configuration is set or that you did not make a typo
2023-02-21 19:39:30,919 WARN  [io.qua.config] (main) Unrecognized configuration key "quarkus.oidc.auth-server-url" was provided; it will be ignored; verify that the dependency extension for this configuration is set or that you did not make a typo
2023-02-21 19:39:31,637 INFO  [com.raj.sup.sit.AppLifecycleBean] (main) The application is starting...published staged archived /var/www/artifact /var/www/upload /var/www/orgfiles
WARNING: duplicate route registered for RenardeFormLoginController.login
2023-02-21 19:39:31,701 INFO  [io.quarkus] (main) qute-support-site 1.0.0-SNAPSHOT on JVM (powered by Quarkus 2.16.1.Final) started in 0.950s. Listening on: http://0.0.0.0:8080
2023-02-21 19:39:31,702 INFO  [io.quarkus] (main) Profile prod activated. 
2023-02-21 19:39:31,702 INFO  [io.quarkus] (main) Installed features: [cdi, hibernate-validator, mailer, narayana-jta, qute, reactive-routes, renarde, resteasy-reactive, resteasy-reactive-jackson, resteasy-reactive-qute, security, smallrye-context-propagation, smallrye-jwt, smallrye-openapi, swagger-ui, vertx]

I think something is missing?

Expected behavior

To be able to connect to the docker container with the debugger

Actual behavior

Get an error:

Attaching to localhost:5005
handshake failed - connection prematurally closed

How to Reproduce?

No response

Output of uname -a or ver

No response

Output of java -version

JDK 17

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.16.1-Final

Build tool (ie. output of mvnw --version or gradlew --version)

Maven

Additional information

No response

@tmulle tmulle added the kind/bug Something isn't working label Feb 21, 2023
@geoand geoand changed the title Reopen #7890 - Debug port not working in Docker container Debug port not working in Docker container Feb 22, 2023
geoand added a commit that referenced this issue Feb 22, 2023
…ebug port

The run-java.sh script needs `JAVA_DEBUG` to enabled debugging, but
we also need to override the host and port by using `JAVA_DEBUG_PORT=*:5005`
because otherwise the JVM process listens on the container's localhost
which is not accessible from the host machine trying to connect remotely

Fixes: #31330
@geoand
Copy link
Contributor

geoand commented Feb 22, 2023

You are correct!

#31332 should address the issue

@geoand geoand self-assigned this Feb 22, 2023
@tmulle
Copy link
Contributor Author

tmulle commented Feb 22, 2023

@geoand Thanks for the tip!

Adding -e JAVA_DEBUG_PORT=*:5005 to my command line provides the proper output and I can now connect to the docker instance via the Remote Debugging port.

My command line:
docker run -i --rm -p 5005:5005 -p 8080:8080 -e JAVA_DEBUG_PORT='*:5005' -e JAVA_DEBUG=true ....

Output from Docker:

Starting the Java application using /opt/jboss/container/java/run/run-java.sh ...
INFO exec  java -Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 -XX:+UseParallelGC -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=20 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -XX:+ExitOnOutOfMemoryError -cp "." -jar /deployments/quarkus-run.jar
Listening for transport dt_socket at address: 5005

@geoand
Copy link
Contributor

geoand commented Feb 22, 2023

👌

geoand added a commit to geoand/quarkus that referenced this issue Feb 22, 2023
…ebug port

The run-java.sh script needs `JAVA_DEBUG` to enabled debugging, but
we also need to override the host and port by using `JAVA_DEBUG_PORT=*:5005`
because otherwise the JVM process listens on the container's localhost
which is not accessible from the host machine trying to connect remotely

Fixes: quarkusio#31330
@tmulle
Copy link
Contributor Author

tmulle commented Feb 22, 2023

@geoand Quick question on this topic of Dockerfile.

Can you tell me why you use USER=185 when building the docker images? Is that a special user?

I noticed it in the .JVM and .LEGACY versions of the file.

# We make four distinct layers so if there are application changes the library layers can be re-used
COPY --chown=185 target/quarkus-app/lib/ /deployments/lib/
COPY --chown=185 target/quarkus-app/*.jar /deployments/
COPY --chown=185 target/quarkus-app/app/ /deployments/app/
COPY --chown=185 target/quarkus-app/quarkus/ /deployments/quarkus/

EXPOSE 8080
EXPOSE 5005

USER 185
...

@geoand
Copy link
Contributor

geoand commented Feb 22, 2023

I can't say I know

geoand added a commit to geoand/quarkus that referenced this issue Feb 23, 2023
…ebug port

The run-java.sh script needs `JAVA_DEBUG` to enabled debugging, but
we also need to override the host and port by using `JAVA_DEBUG_PORT=*:5005`
because otherwise the JVM process listens on the container's localhost
which is not accessible from the host machine trying to connect remotely

Fixes: quarkusio#31330
geoand added a commit that referenced this issue Feb 23, 2023
Update instructions on running container built with Dockerfile with debug port
@quarkus-bot quarkus-bot bot added this to the 3.0 - main milestone Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment