Skip to content

Instantly share code, notes, and snippets.

@wesleyegberto
Created November 9, 2024 23:47
Show Gist options
  • Save wesleyegberto/914eb694e40b8a6fa53d31b44b0c6b28 to your computer and use it in GitHub Desktop.
Save wesleyegberto/914eb694e40b8a6fa53d31b44b0c6b28 to your computer and use it in GitHub Desktop.
JConsole Accessing JVM inside Docker container
FROM maven:3.9-eclipse-temurin-17-alpine AS builder
WORKDIR /app
COPY pom.xml .
RUN mvn verify --fail-never
COPY src ./src
RUN mvn package
FROM ibm-semeru-runtimes:open-17-jre-centos7
WORKDIR /app
EXPOSE 8080 48080
COPY --from=builder /app/target/my-app.jar my-app.jar
# replace <HOST_IP> with the node host
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", \
"-Dcom.sun.management.jmxremote", "-Djava.rmi.server.hostname=<HOST_IP>", \
"-Dcom.sun.management.jmxremote.port=48080", "-Dcom.sun.management.jmxremote.rmi.port=48080", \
"-Dcom.sun.management.jmxremote.ssl=false", "-Dcom.sun.management.jmxremote.authenticate=false", \
"-jar", "my-app.jar"]
# run container exposing ports
docker run -d -p 8080:8080 -p 48080:48080 myorg/myapp-1.0
# Run JConsole and access remote process 127.0.0.1:48080, if running local, or NODE_IP:48080
jconsole
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment