Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
boot2docker-jmxremote-example
FROM java:8
COPY Main.java /
RUN javac Main.java
public class Main {
public static void main(String[] args) {
while (true) {}
}
}
#!/bin/sh
JMX_PORT=${1:-1099}
IMAGE_NAME=boot2docker-jmxremote-example
CONTAINER_NAME=$IMAGE_NAME
# Build docker image
docker build -t $IMAGE_NAME .
# Run docker container
docker run --name $CONTAINER_NAME -d --expose $JMX_PORT -p $JMX_PORT:$JMX_PORT $IMAGE_NAME \
java -Dcom.sun.management.jmxremote.port=$JMX_PORT \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.rmi.port=$JMX_PORT \
-Djava.rmi.server.hostname=$(boot2docker ip) \
Main
STATUS=$?
# Start visualvm or jconsole
if [ $STATUS -eq 0 ]; then
jvisualvm --openjmx $(boot2docker ip):$JMX_PORT
# jconsole $(boot2docker ip):$JMX_PORT
fi
# Delete docker container
docker rm -f $CONTAINER_NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.