Dynamically set JAVA_HOME of docker container
My docker container requires JAVA_HOME to be set. I have added it to the Dockerfile as below
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/jre
However, this is a hardcoding of the value. Is there a way I can get this value dynamically from the image itself
2 Solutions collect form web for “Dynamically set JAVA_HOME of docker container”
The image built from a Dockerfile is forever static. Its Java location will never change unless rebuilt.
When the image is started as a container, however, anything can happen. If there’s any scripts that will edit the Java location during runtime, then this script is probably also where
JAVA_HOME should be updated.
If you mean that you want to dynamically build your image using an arbitrary base image with differing java location then this should probably be handled by a build script.
May be you can do something like this in CMD :
# rpm -qa | grep java-1.8 java-1.8.0-openjdk-126.96.36.199-2.b11.el7_3.x86_64
#rpm -ql java-1.8.0-openjdk | sed -n '1p' | cut -d/ -f1-5 /usr/lib/jvm/java-1.8.0-openjdk-188.8.131.52-2.b11.el7_3.x86_64