Remote debugging is a common practice for troubleshooting issues in software development.
If you are using Tomcat or TomEE with Docker containers as part of your stack you can find various techniques to enable debug capabilities in these types of containers:
1. Create a custom Docker image by extending an existing official one
2. Extensive customization of CATALINA_OPSTS
However, both approaches require extra steps in some scenarios. Below I share the simplest method I have used to do remote debugging in Apache Tomcat and Apache TomEE with a Docker image:
$ $ docker run -it -p 8080:8080 -p 8000:8000 -e CATALINA_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8000" tomcat:9.0.17-jre11
- Runs a docker container
- Enables interactive mode for the container. This allocates a pseudo-tty and keeps STDIN open even if not attached.
-p 8080:8080 -p 8000:8000
- Exposes containers port to the docker host
- Minimum customization for CATALINA_OPTS to enable debug mode, useful for the majority of cases
- Image and label from the Docker container we want to run.
Thank you, works great with tomee:8.0.1-plume image!