How do I attach VisualVM to a simple Java process running in a Docker container

后端 未结 6 1762
礼貌的吻别
礼貌的吻别 2020-12-12 14:35

Actually I wanted a solution working for JEE containers, specifically for Glassfish, but after I tried many combinations of settings and did not succeed, I reduced the setup

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-12 14:59

    As answered by Anthony. I had to use the -Djava.rmi.server.hostname java option on my Windows machine.

    Just be sure not to use the CMD in JSON format in your Dockerfile as this doesn't support shell expansion.

    Dockerfile example:

    FROM java:8
    COPY . /usr/src/myapp
    WORKDIR /usr/src/myapp
    RUN javac Main.java
    #Do not use CMD in JSON format here because shell expansion doesn't work in JSON format
    #Shell expansion is needed for the ${HOST} variable.
    CMD java -Dcom.sun.management.jmxremote=true \
    -Dcom.sun.management.jmxremote.rmi.port=9010 \
    -Dcom.sun.management.jmxremote.port=9010 \
    -Dcom.sun.management.jmxremote.ssl=false \
    -Dcom.sun.management.jmxremote.authenticate=false \
    -Dcom.sun.management.jmxremote.local.only=false \
    -Djava.rmi.server.hostname=${HOST} \
    Main
    

提交回复
热议问题