Debugging Java containers

less than 1 minute read | By Prasad K.

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"\]

\
  1. Build the docker and run with exposing the app port and debug port.</font>

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

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

image

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