Search code examples
javaspringspring-bootdockerremote-debugging

Remote debug Spring Boot application


I've a simple (dockerized) Web Application in Spring Boot.

The App compile correctly. The container build fine without errors. The App is running fine on localhost:8080, It's a simple "Hello World".

Now I'm trying to attach Spring Tool Suite debugger to the containerized JVM with Remote debugging but without success.

The fault message is

Failed to connect to remote VM com.sun.jdi.connect.spi.ClosedConnectionException

This is my Dockerfile:

FROM openjdk:8-alpine
WORKDIR /
EXPOSE 8080 8000
COPY target /

and that's my docker-compose.yml

version: '3.7'
services:
  web:
    build: .
    ports:
      - "8080:8080"
      - "8000:8000"
    command: java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=127.0.0.1:8000 -jar gs-spring-boot-docker-0.1.0.jar

In Spring Tool Suite I have these settings for remote debugging:

Remote Java Application
- Connection type: Standard (Socket attach)
- Host: localhost
- port: 8000

I'm using a Macbook Pro with OSX Mojave (10.14.6) Thanks for any suggetion.


Solution

  • tl;dr:

    The incorrect part is address=127.0.0.1:8000 it should be 0.0.0.0:8000

    Full command in the docker compose:

    command: java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:8000 -jar gs-spring-boot-docker-0.1.0.jar
    

    Long answer:

    Every container has its own network interface, keeping that in mind 127.0.0.1 means loopback interface and its only accessible from the same host (ie. if you are inside the container you can access it).

    In contrast if you want the application to listen on every network interface available, we can swap it with 0.0.0.0 which is in our case what we want, because we are connecting from outside of the container to the debugging port which is 8000 inside the container so loopback interface is not sufficient.