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
It's possible add the JAVA_HOME in a ENV Dockerfile instruction. But if the Java package is updated you have to change the ENV JAVA_HOME in your Dockerfile.
But I found a method to set the JAVA_HOME automatically without update the Dockerfile.
RUN export JAVA_HOME="$(dirname $(dirname $(readlink -f $(which java))))"
I hope this can help you.