Java – jcmd not found?
The jcmd
is available at the JDK/bin
, not JRE. Make sure the installed Java is JDK, not JRE.
Let review the following example, try to use jcmd
to enable Java Flight Recorder inside a docker container.
1. DockerFile
A simple Dokcerfile.
Dockerfile
FROM adoptopenjdk/openjdk11:alpine-jre
ARG JAR_FILE=target/markdown.jar
WORKDIR /opt/app
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","app.jar"]
2. Docker + jcmd
Access into the docker container’s shell, try jcmd
to enable the Java Flight Recorder, but hits command not found?
Terminal
$ docker exec -it 3d1588519433 sh
/opt/app # jcmd
sh: jcmd: not found
/opt/app # which java
/opt/java/openjdk/bin/java
/opt/app # java -version
openjdk version "11.0.7" 2020-04-14
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.7+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.7+10, mixed mode)
/opt/app #
Solution
Again, the jcmd
is available at the JDK/bin
, not JRE. The Dockerfile
is using the openjdk11:alpine-jre
, JRE image.
Dockerfile
FROM adoptopenjdk/openjdk11:alpine-jre
To fix it, try to install the JDK image.
Dockerfile
FROM adoptopenjdk/openjdk11:alpine
Test it again.
Terminal
$ docker exec -it <container ID> sh
/opt/app # jcmd
48 jdk.jcmd/sun.tools.jcmd.JCmd
1 app.jar
Done.
References
About Author
Comments
Subscribe
0 Comments