Debugging Tomcat in Docker container

The accepted answer didn't work for me, apparently because I was using Java 11. It seems that if you're using Java 9 or newer, you need to specify the JPDA address like this:

JPDA_ADDRESS=*:8100

This is the command I use for this:

docker run -it --rm \
  -e JPDA_ADDRESS=8000 \
  -e JPDA_TRANSPORT=dt_socket \
  -p 8888:8080 \
  -p 9000:8000 \
  -v D:/tc/conf/tomcat-users.xml:/usr/local/tomcat/conf/tomcat-users.xml \
  tomcat:8.0 \
  /usr/local/tomcat/bin/catalina.sh jpda run

Explanation

  • -e JPDA_ADDRESS=8000
    debugging port in container, passed as environment variable
  • -e JPDA_TRANSPORT=dt_socket
    transport type for debugging as socket, passed as environment variable
  • -p 8888:8080
    expose tomcat port 8080 on host as port 8888
  • -p 9000:8000
    expose java debugging port 8000 on host as port 9000
  • -v {host-file}:{container-file}
    overwrite tomcat-user.xml with my local on, since I need access to the manager api
    omit this line if this isn't necessary for your use case
  • tomcat:8.0
    see https://hub.docker.com/_/tomcat/
  • /usr/local/tomcat/bin/catalina.sh jpda run
    command to run in the container