使用远程调试运行 docker-compose英特尔,Java 11

问题描述

我将指南中的步骤应用于我的项目 (https://www.jetbrains.com/help/idea/run-and-debug-a-spring-boot-application-using-docker-compose.html)。 总而言之,我将此行添加到 Dockerfile -Djava.security.egd=file:/dev/./urandom 和命令 docker-compose command: java -Djava.security.egd=file:/dev/./urandom -jar /usr/app/test-app.jar。 在docker-compose中点击command附近的debug按钮后,远程配置为:

Debugger mode: Attach to remote JVM
Transport: Socket
Host: localhost
Port: 5005
Command line arguments for remote JVM: -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005;

Docker Compose 运行配置(启动前)选项:

--------------------------------------------------
Port               | Local port | Container port |
-------------------------------------------------|
Java Debugger port | 5005       | 5005           |
--------------------------------------------------

Custom command: java -agentlib:jdwp=transport=dt_socket,suspend=y,address=5005 -Djava.security.egd=file:/dev/./urandom -jar /usr/app/test-app.jar
Custom options: -p 5005:5005

运行配置我收到异常: Error running 'Remote JVM Debug with compose': Unable to open debugger port (localhost:5005): java.net.ConnectException "Connection refused: connect"

我尝试通过将地址更改为 *:<port>解决此问题。 生成自定义命令是 java -agentlib:jdwp=transport=dt_socket,address=*:5005 -Djava.security.egd=file:/dev/./urandom -jar /usr/app/test-app.jar。 然后我得到异常: Error running 'Remote JVM Debug with compose': Unable to open debugger port (localhost:5005): java.io.IOException "handshake Failed - connection prematurally closed"。 我也尝试将端口更改为 8080,但结果是一样的。如何解决此问题并使用 docker-compose(启动前)进行远程配置? 演示问题的项目:https://github.com/leonaugust/intelij_docker_problem

Dockerfile

# Build stage
FROM maven:3.6.0-jdk-11-slim AS build
copY src /usr/src/app/src
copY pom.xml /usr/src/app
RUN mvn -f /usr/src/app/pom.xml clean package -DskipTests

# Run stage
FROM adoptopenjdk/openjdk11:alpine-jre
copY --from=build /usr/src/app/target/test-app.jar /usr/app/test-app.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","-Djava.security.egd=file:/dev/./urandom","/usr/app/test-app.jar"]

docker-compose.yml

version: '3.1'
services:

  test-app:
    build: .
    container_name: test-app
    image: test-app

    ports:
      - 8080:8080
    command: java -Djava.security.egd=file:/dev/./urandom -jar /usr/app/test-app.jar

解决方法

Dockerfile 中尝试:

ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/usr/app/test-app.jar"]

,

ENTRYPOINT 中的关键字 Dockerfile 更改为 CMD