1

I have an issue that I am investigating in a Java application that is hosted in a Docker service. The application is a REST API that has it's own docker service

I have added extra logging and looked into the service logs as well as exec-ing into the container and looking at logs there, but that only gets me to a certain point.

Is there any way to attach a remote debugger, or something similar so that I can step through the code of the application?

4
  • 1
    Look into stackoverflow.com/questions/975271/… but note that you shouldn’t do this in production Commented Sep 11, 2018 at 10:59
  • Depending on the container you are using you should change the command started by the container. Usually you can add parameters passing the JAVA_OPT environment variable. Can you provide some more info about the container? Commented Sep 11, 2018 at 13:00
  • @GianlucaMereu My application is deployed using a docker compose file with three different services defined. One of these services is the one which I would like to debug. Commented Sep 11, 2018 at 14:54
  • Check this link for detailed steps Visit <stackoverflow.com/a/61660010/1734444>? Commented May 7, 2020 at 14:18

2 Answers 2

4

Dockerfile e.g.:

FROM openjdk:11.0.1-jdk
VOLUME /tmp
COPY build/libs/*.jar app.jar
EXPOSE 5005
EXPOSE 8080
ENTRYPOINT ["java", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005", "-Dspring.profiles.active=localdocker","-jar","/app.jar"]

then connect by remote debugger from Idea or Eclipse

Sign up to request clarification or add additional context in comments.

1 Comment

This works. I was missing * in address=*:5005. Thanks!
1

You can also leave your docker file the same if you do something like:

VOLUME /tmp
COPY build/libs/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java"]
CMD ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005", "-Dspring.profiles.active=localdocker","-jar","/app.jar"]

And then on the terminal pass the neccessary arguments

docker run -p 5005:5005 <my-container> -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005, -Dspring.profiles.active=localdocker,-jar,/app.jar

This is the documentation for the connection options for jdwp. https://docs.oracle.com/javase/7/docs/technotes/guides/jpda/conninv.html#Transports

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.