Share via


Debugging Java containers

Can you debug Java applications within your container? Yes.

How? Check below…

1. Modify your dockerfile

  • To expose JPDA params

                 ENV JPDA_OPTS="-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n"

  • To expose the debug port along with application port

                 EXPOSE 7080 8000

  • To add the options in your command

               CMD ["sh", "-c", "java $JPDA_OPTS -Durl=$url -jar app.jar"]

2. Build the docker and run with exposing the app port and debug port.

               docker run –d -p 7080:7080 <docker image>

3. Open the project in Eclipse and create a debug configuration with Host and debug port

image

4. Set the breakpoints and Launch the debug configuration. Voila! You are debugging the application in running container.