-
-
Save telekosmos/603543c8b9262bf6668ae72a82bf1109 to your computer and use it in GitHub Desktop.
Remote Debugging a Java Application Inside a Docker Container
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
One problem when trying to debug a Java application running inside a Docker container is: | |
You can't expose an additional port when re(starting) a Docker container. | |
Here are the steps I used to create a remote debugging session for Planets: | |
In our scenario we can't simply override the Dockerfile CMD or pass an environment variable JAVA_OPTS to enable remote debugging. | |
So we have to "enter" the container with exec and add the JAVA_OPTS to the start script there: | |
$ docker exec -it planets-staging /bin/bash | |
# vi eclipse.ini | |
<append JAVA_OPTS="-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n"> | |
Next we create a snapshot of the container and stop it afterwards. | |
$ docker commit planets-staging debug/staging-snapshot | |
$ docker stop planets-staging | |
Now we can expose an additional port for remote debugging when we run the snapshot: | |
$ docker run -i -p 80:80 -p 8000:8000 debug/staging-snapshot | |
Just for completeness in case you have a scenario where you can pass JAVA_OPTS as environment to your start script. | |
$ docker run -i -p 80:80 \ | |
-e "JAVA_OPTS=\"-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n\"" \ | |
-p 8000:8000 debug/staging-snapshot | |
Happy remote debugging! | |
Pd: not tried :-S | |
Credits to: https://devops.datenkollektiv.de/remote-debugging-a-java-application-inside-a-docker-container.html |
I have found that I explicitly need to bind to all interfaces to make it work, either address=0.0.0.0:8000 or address=*:8000
This works!!!
I have found that I explicitly need to bind to all interfaces to make it work, either address=0.0.0.0:8000 or address=*:8000
This works!!!
I'll give a big 'ol +1 on this one: added *:8000 was the only thing that worked for me
@telekosmos and @pfrandsen thank you! this gist and *:8000 save my day! "big 'ol +1" indeed!!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have found that I explicitly need to bind to all interfaces to make it work, either address=0.0.0.0:8000 or address=*:8000