简体   繁体   English

远程调试 Spring 引导应用程序

[英]Remote debug Spring Boot application

I've a simple (dockerized) Web Application in Spring Boot.我在 Spring 引导中有一个简单的(dockerized)Web 应用程序。

The App compile correctly.该应用程序编译正确。 The container build fine without errors.容器构建良好,没有错误。 The App is running fine on localhost:8080, It's a simple "Hello World".该应用程序在 localhost:8080 上运行良好,这是一个简单的“Hello World”。

Now I'm trying to attach Spring Tool Suite debugger to the containerized JVM with Remote debugging but without success.现在我正在尝试将 Spring 工具套件调试器附加到容器化 JVM 并进行远程调试,但没有成功。

The fault message is故障信息是

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

This is my Dockerfile:这是我的 Dockerfile:

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

and that's my docker-compose.yml那是我的 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:在 Spring 工具套件中,我有这些用于远程调试的设置:

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.我正在使用带有 OSX Mojave (10.14.6) 的 Macbook Pro 感谢您的建议。

tl;dr: tl;博士:

The incorrect part is address=127.0.0.1:8000 it should be 0.0.0.0:8000不正确的部分是address=127.0.0.1:8000它应该是0.0.0.0:8000

Full command in the docker compose: docker 中的完整命令组成:

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).每个容器都有自己的网络接口,请记住127.0.0.1表示环回接口,并且只能从同一主机访问(即,如果您在容器内,则可以访问它)。

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.相反,如果您希望应用程序侦听每个可用的网络接口,我们可以将其与0.0.0.0交换,这在我们的例子中是我们想要的,因为我们从容器外部连接到调试端口,即 8000 内部容器所以环回接口是不够的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM