Remote debugging is a common practice for troubleshooting issues in software development.
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.