Search code examples
springdockertomcatremote-debuggingtomcat9

Access Tomcat debug port outside container


I have a container running java backend on a tomcat server. I would like to configure it so that I can attach my eclipse to debug my code. There is a lot of documentation but with so many different and contradictory answers, I can't find a way to do it.

here is my current configuration :

DockerFile :

From tomcat:9.0-jdk8-openjdk
   
ADD ./application.war /usr/local/tomcat/webapps/
ADD tomcat-users.xml /usr/local/tomcat/conf/tomcat-users.xml
ADD server.xml /usr/local/tomcat/conf/server.xml
EXPOSE 9090
CMD ["catalina.sh","run"]

And the command to run the docker :

docker run -d -p 9090:8080 myApp

What should I add to make my application accessible to remote debugging ?


Solution

  • the solution I found was : DockerFile

    From tomcat:9.0-jdk8-openjdk
       
    ADD ./application.war /usr/local/tomcat/webapps/
    ADD tomcat-users.xml /usr/local/tomcat/conf/tomcat-users.xml
    ADD server.xml /usr/local/tomcat/conf/server.xml
    EXPOSE 9090
    EXPOSE 9000
    ENV JPDA_ADDRESS=8000
    ENV JPDA_TRANSPORT=dt_socket
    
    CMD ["catalina.sh", "jpda", "run"]
    

    and then : docker run -d -p 9090:8080 -p 9000:8000 myApp after building the image.

    Warning : this makes the application debuggable only from the server where the docker is running (in localhost:9000 in that example)! I read there is something to do with *:JPDA_ADDRESS but I could not make it work.