Ok. I figured it out. In my case, it's a little different since I am not using a fat jar.
My Dockerfile
looks like this:
# extract layers
FROM adoptopenjdk:11-jre-hotspot as builder
WORKDIR /application
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} application.jar
RUN java -Djarmode=layertools -jar application.jar extract
# copy layers
FROM adoptopenjdk:11-jre-hotspot
WORKDIR /application
COPY --from=builder /application/dependencies/ ./
COPY --from=builder /application/spring-boot-loader/ ./
COPY --from=builder /application/snapshot-dependencies/ ./
COPY --from=builder /application/application/ ./
VOLUME /files
# ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"]
ENTRYPOINT ["java","-agentlib:jdwp=transport=dt_socket,address=*:8000,server=y,suspend=n","-Djava.security.egd=file:/dev/./urandom","org.springframework.boot.loader.JarLauncher"]
Notice the last line. It has all the features to enable the app to be remotely debugged.
Now, In the ports section of my compose I have:
ports:
- 8080:8080
- 8000:8000
Both ports are needed in this case. Because the debugger will be attached to the one mentioned in the Dockerfile, while the other one is the regular entry point of the app.
Now, inside .vscode/launch.json
, all we need to do is point to that port.
{
"type": "java",
"name": "Debug (Attach)",
"projectName": "pdf-tools-webapi",
"request": "attach",
"hostName": "localhost",
"port": 8000
}
Then, if you hit the other port, it should stop to debug! :)
