Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change JAVA_HOME in docker

The legacy web application which I want to dockerise uses some old classes like com/sun/image/codec/jpeg/ImageFormatException which were supported till Java SE7. Now in the docker container default jdk getting (on installing tomcat-6 container) is

java version "1.7.0_131"
OpenJDK Runtime Environment (IcedTea 2.6.9) (7u131-2.6.9-2~deb8u1)

OpenJdk doesn't support these classes

I used update-alternatives to install Oracle Jdk7.80

After loading container, on giving java -version I am getting

java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)

However, echo $JAVA_HOME after entering the container gives /docker-java-home/jre which again points to OpenJdk. How can I set JAVA_HOME to the Oracle Jdk home that I installed?

like image 844
Shoreki Avatar asked Sep 18 '17 10:09

Shoreki


2 Answers

You can simply set/change environment variables of your docker image by using the ENV command in your Dockerfile:

ENV JAVA_HOME /path/to/java
like image 156
dpr Avatar answered Oct 19 '22 10:10

dpr


If your base image contains by default OpenJDK and If you want to use OracleJDK in your image just add the below command to your dockerfile and build the image and boom your image will have oracle JDK.

RUN yum -y remove java***
RUN yum localinstall -y jdk-8u212-linux-x64.rpm && \
    echo "JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")" | tee 
    -a /etc/profile && source /etc/profile && echo $JAVA_HOME && \
    rm jdk-8u212-linux-x64.rpm && \ 
    alternatives --set java /usr/java/jdk1.8.0_212-amd64/jre/bin/java
like image 37
Dashrath Mundkar Avatar answered Oct 19 '22 11:10

Dashrath Mundkar