0

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 ?

Arcyno
  • 4,153
  • 3
  • 34
  • 52
  • Does this answer your question? [How to start debug mode from command prompt for apache tomcat server?](https://stackoverflow.com/questions/16689274/how-to-start-debug-mode-from-command-prompt-for-apache-tomcat-server) – Piotr P. Karwasz May 25 '21 at 14:00

1 Answers1

2

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.

Arcyno
  • 4,153
  • 3
  • 34
  • 52
  • 1
    `JPDA_ADDRESS=8000` works only up to Java 8 (cf. [Baeldung](https://www.baeldung.com/java-application-remote-debugging)). A more universal solution would be `JPDA_ADDRESS=*:8000`. Remark also that you are exporting the wrong ports: in should be `EXPOSE 8080` and `EXPOSE 8000`. – Piotr P. Karwasz May 26 '21 at 21:04
  • well no I expose the mapped port (look at the `docker run` command below). I will try with `*:` – Arcyno May 26 '21 at 21:12
  • 1
    Yes, you override the default port mappings, however the purpose of `EXPOSE` is to give default port mappings (cf. [documentation](https://docs.docker.com/engine/reference/builder/#expose). – Piotr P. Karwasz May 26 '21 at 21:18
  • 1
    OK I learned something.. So it is basically "useless" to put the `EXPOSE` command ? It acts as documentation ? – Arcyno May 26 '21 at 21:22