Last active
July 9, 2023 06:46
-
-
Save joe-mccann-dev/a09a89294632912becc46b4ba68c7811 to your computer and use it in GitHub Desktop.
Attach Debugger to Remote JVM using Debugger for Java Extension in VS Code when using Docker containers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# syntax=docker/dockerfile:1 | |
FROM eclipse-temurin:17-jdk-jammy as base | |
WORKDIR /app | |
COPY .mvn/ .mvn | |
COPY mvnw pom.xml ./ | |
RUN ./mvnw dependency:resolve | |
COPY src ./src | |
FROM base as development | |
# exposing 8000 in development enables attaching to remote jvm debugger | |
EXPOSE 8000 | |
CMD ["./mvnw", "spring-boot:run", "-Dspring-boot.run.profiles=mysql", "-Dspring-boot.run.jvmArguments='-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8000'"] | |
FROM base as build | |
RUN ./mvnw package | |
FROM eclipse-temurin:17-jre-jammy as production | |
EXPOSE 8080 | |
COPY --from=build /app/target/spring-petclinic-*.jar /spring-petclinic.jar | |
CMD ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/spring-petclinic.jar"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.2.0", | |
"configurations": [ | |
{ | |
"type": "java", | |
"name": "Attach to Remote JVM", | |
"projectName": "spring-petclinic", | |
"request": "attach", | |
"hostName": "localhost", | |
"port": "8000", | |
}, | |
] | |
} | |
Author
joe-mccann-dev
commented
Jul 9, 2023
•
- following Docker Java tutorial here: https://docs.docker.com/language/java/develop/
- when you get to the "Connect to Debugger" section, they provide instructions for IntelliJ but not for VS Code
- Under "Run and Debug", click dropdown near green play button and then select "Add Configuration"
- initially I had difficulty connecting VS Code Debugger for Java extension to remote jvm in Docker container.
- required exposing port 8000 in development, e.g. Dockerfile below "FROM base as development \ EXPOSE 8000"
- projectName was required for 'watch' feature of debugger and is root directory of project
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment