Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

debug spring-boot in docker

For some reason I have issues connecting remote debug to a spring-boot app running inside docker. I start the java app with:

java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n -jar app.jar

For docker I expose these ports on docker-compose:

ports:
- "8080:8080"
- "8000:8000"

However, the debugger is not able to connect on port 8000. It works when I run the server locally but not inside docker. Any idea why?

Docker ps output:

CONTAINER ID        IMAGE                       COMMAND                CREATED               STATUS              PORTS                                            NAMES
0d17e6851807        pocmanager_manager:latest   "/bin/sh -c 'java -D   3 seconds ago       Up 2 seconds        0.0.0.0:8000->8000/tcp, 0.0.0.0:8080->8080/tcp   pocmanager_manager_1   
35ed2e2c32bc        redis:latest                "/entrypoint.sh redi   14 seconds ago      Up 13 seconds       0.0.0.0:6379->6379/tcp                           pocmanager_redis_1
like image 814
Jarle Hansen Avatar asked Jun 26 '15 10:06

Jarle Hansen


People also ask

Can I debug in Docker?

The Docker extension currently supports debugging Node. js, Python, and . NET applications within Docker containers.


1 Answers

i have to realize that in the dockerFile the Expose command only do the half of work, this mean that only expose the port inside the docker, but not outside, in your example the result will be like this:

enter image description here

Debug works with the JAVA_OPTS and remote debug, the dockerFile looks like this:

FROM frolvlad/alpine-oraclejdk8:slim
VOLUME /tmp
ADD gs-spring-boot-docker-0.1.0.jar app.jar
RUN sh -c 'touch /app.jar'
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -jar /app.jar" ]

and executing this command:

docker run -e "JAVA_OPTS=-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=y" -p 8080:8080 -p 8000:8000 -t springio/gs-spring-boot-docker

As you can see, you should expose the debug port, during the run, in my case(eclipse) 8000

enter image description here

enter image description here

like image 104
nekperu15739 Avatar answered Oct 04 '22 06:10

nekperu15739