Reputation: 1726
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?
Upvotes: 1
Views: 4738
Reputation: 111
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
Upvotes: 1
Reputation: 330
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
Upvotes: 4