Debug spring-boot in docker

For some reason, I am having trouble debugging the spring-boot application running inside the docker remotely. I am launching a java application with:

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

For docker, I expose these ports to docker-compose:

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

However, the debugger cannot connect to port 8000. It works when I start the server locally, but not inside the 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 
+8
java spring spring-boot docker
source share
3 answers

I should understand that in dockerFile the Expose command does only half the work, this means that only exposing the port is inside the docker, but not outside, in your example the result will be like this:

enter image description here

Debugging works with JAVA_OPTS and remote debugging, 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 run the following 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 have to open the debug port at runtime in my case (eclipse) 8000

enter image description here

enter image description here

+7
source share

Hi, I ran into the same problem.

I added the following to the entry point to the Docker file:

"- agentlib: JDWP = transport = socket transport, address = 8000, server = y, suspend = n"

Now it looks like this:

 FROM java:8 VOLUME /tmp ADD realName*.jar app.jar EXPOSE 4786 RUN sh -c 'touch /app.jar' ENTRYPOINT ["java","-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] 

I do not Expose port 8000 in the Docker file.

Hope this helps.

+6
source share

I think the reason for this may be that your Virtual Box virtual configuration does not tunnel the debug port on the host machine.

Check this link https://github.com/boot2docker/boot2docker/blob/master/doc/WORKAROUNDS.md

Basically, in your case you need to request a command and run

VBoxManage modifyvm "boot2docker-vm" --natpf1 "tcp-port8000,tcp,,8000,,8000";

Note. Make sure VBoxManage is in your PATH

0
source share

All Articles