Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting Eclipse to Docker Container for Remote Debugging

I'm trying to connect eclipse to a docker container I have running but I am having trouble.

My docker run command is as follows:

docker run --rm -it -p 8000:8000 -p=8668:8080 -p 8010:8009 -p 8443:8443 \
--name myContainer -h theContainer -e JVM_ROUTE=myContainer1 myContainer:qa

In eclipse, I'm connecting with localhost as the host, and 8000 as the port. I go to Run->Debug Configurations->Remote Java Application, and I've created a new debug configuration.

my project debugging

When I click apply, then debug, I get a pop up error message Failed to connect to remote VM.

cant connect

What else do I need to do to get remote debugging working properly?

like image 839
aCarella Avatar asked Apr 10 '18 15:04

aCarella


People also ask

How do you attach a debugger to a Docker container?

To attach to a running process in a Windows Docker container: In Visual Studio, select Debug > Attach to Process (or CTRL+ALT+P) to open the Attach to Process dialog box. Set the Connection type to Docker (Windows Container). Select Find... to set the Connection target using the Select Docker Container dialog box.

Can I run Eclipse in a Docker container?

Eclipse Che is a next-generation cloud IDE and workspace server that can run anywhere Docker runs.


1 Answers

A java application running in a docker container can be remotely debugged by

  1. Enabling JDWP for the java process in the container, e.g.

    java -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y [...]
    

    or using the JAVA_OPTS environment variable

    JAVA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y"
    

    Note that suspend=y will prevent the application from starting until a remote debugger is attached to the JVM. If suspend=n is used, the application will start as normal allowing a remote debugger to connect at a later time.

  2. Connecting to the process, e.g. through your IDE, using the port specified in the address=<port> settings above, and importantly the ip address of the docker host which, unless you are running on linux, is probably not localhost. If you are using docker-machine, the docker host ip can be displayed using docker-machine ip, e.g.

    $ docker-machine ip
    192.168.99.100
    
like image 144
codemonkey Avatar answered Sep 24 '22 01:09

codemonkey