问题
I'm very new to Docker so this could be something simple I'm doing wrong. With all the solutions out there I've been able to get remote debugging working with eclipse when using 'Docker run' to launch the Tomcat container.
docker run -it --rm -e JPDA_ADDRESS=8000 -e JPDA_TRANSPORT=dt_socket -p 8888:8080 -p 8000:8000 tomcat:8.0-jre8 /usr/local/tomcat/bin/catalina.sh jpda run
However when using docker-compose, I get a "Failed to connect to remote VM. Connection refused" dialog.
docker-compose up
docker-compose.yml settings:
tomcat:
image: tomcat:8.0-jre8
# START - REMOTE DEBUGGING SETTINGS
# Didn't work with or without this network_mode setting. But the bridge settings as seen with 'docker container inspect *CID*' looks almost identical to the working solution
network_mode: bridge
environment:
- JPDA_ADDRESS:8000
- JPDA_TRANSPORT:dt_socket
entrypoint: /usr/local/tomcat/bin/catalina.sh jpda run
# END - REMOTE DEBUGGING SETTINGS
deploy:
restart_policy:
condition: on-failure
placement:
constraints: [node.role == manager]
ports:
- 8888:8080
# REMOTE DEBUGGING SETTINGS jpda port
- 8000:8000
My eclipse settings that work with 'docker run' are:
Remote Java Application:
Host: localhost
Port: 8000
Note: With the docker-compose settings I also see the expected print in the startup output:
Listening for transport dt_socket at address: 8000
and also with both deployments I can access the web service's functionality through the exposed port 8888. ie. This simple link returns 'Hello'.
http://localhost:8888/MyEmulatorService/rest/MES/
Any thoughts on why I can't remote debug when launching this way? I suspect there's a subtle difference in the way the network configuration is setup.
回答1:
A buddy of mine figured this out. Even though the startup output makes it appear as everything is working and the default port and transport used by catalina.sh is 8000, dt_socket.
The environment variables were not being passed into the container and this was causing the breakage. Maybe someone else can explain how that impacts the .sh script?
This problem was detected by tunneling into the container and listing the environment variables.
docker exec -it *CID* bash
env
The change to my docker-compose.yml file now looks like:
environment:
JPDA_ADDRESS: 8000
JPDA_TRANSPORT: dt_socket
回答2:
Usually we are using
environment:
- JAVA_OPTS= -agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n
来源:https://stackoverflow.com/questions/45383645/remote-debugging-with-jpda-wont-connect-to-tomcat-through-eclipse-when-using-do