简体   繁体   中英

Run docker-compose with remote debug. Intelij, Java 11

I applied the steps from the guide to my project( https://www.jetbrains.com/help/idea/run-and-debug-a-spring-boot-application-using-docker-compose.html ). Summarizing, I added this line to Dockerfile -Djava.security.egd=file:/dev/./urandom and command to docker-compose command: java -Djava.security.egd=file:/dev/./urandom -jar /usr/app/test-app.jar . After clicking on the debug button near command at docker-compose, the remote configuration is:

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 run configuration(Before launch) options:

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

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

Running the configuration I received exception: Error running 'Remote JVM Debug with compose': Unable to open debugger port (localhost:5005): java.net.ConnectException "Connection refused: connect"

I tried to fix this by changing address to *:<port> . The resulting custom command is java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 -Djava.security.egd=file:/dev/./urandom -jar /usr/app/test-app.jar . Then I get exception: Error running 'Remote JVM Debug with compose': Unable to open debugger port (localhost:5005): java.io.IOException "handshake failed - connection prematurally closed" . Also I tried to change the port to 8080, but the result is the same. How to fix this problem and have remote configuration with docker-compose(Before launch)? Project to demonstrate the problem: 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

In a Dockerfile try:

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

Change the keyword ENTRYPOINT in Dockerfile to CMD .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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