I was testing an application (parser.jar) and need to limit the resource used by the app (cpu/ram) and see how different implmenation behaves.
docker run --rm -p 9010:9010 -it --memory=3000MB --cpus="2" java:8-jdk bash -c " java \
-server \
-XX:+UseG1GC \
-XX:+UseStringDeduplication \
-XX:+ExitOnOutOfMemoryError \
-Xmx2g \
-Dcom.sun.management.jmxremote.port=9010 \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.rmi.port=9010 \
-Djava.rmi.server.hostname=$HOST_HOSTNAME \
-jar target/scala-2.11/parser.jar"
Then from visualvm, add JMX by using the docker interface ip (im my case, en0 wit ip 172.18.10.13) and port exposed from previous command (9010)