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

  • ONBUILD in nestled builded Docker images
  • How to determine bridge IP of docker swarm container
  • Create shared package cache folder for a Docker container
  • Access to the docker machine from Android app
  • How to remove configure volumes in docker images
  • Why is the Kafka distributed connector dying when the node I created it on is killed?
  • Access docker.sock from inside a container
  • IBM Bluemix keeps asking for credentials
  • Run docker daemon using specific cgroup mount
  • Pass arguments to parent Dockerfile
  • Exposing ports to all containers, not only the host
  • Point my domain to specific docker container with apache
  • 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-1.8.0.131-2.b11.el7_3.x86_64
    

    and then

    #rpm -ql java-1.8.0-openjdk | sed -n '1p' | cut -d/ -f1-5
    /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.131-2.b11.el7_3.x86_64
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.