Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define OpenJDK 8 in CentOS based Dockerfile?

Assuming that there is a CentOS Dockerfile:

FROM centos

What is the right way of adding OpenJDK 8 for it ?

I have tried to use similar approach as for Fedora https://github.com/projectatomic/docker-fedora-images/blob/master/java-openjdk-8/Dockerfile

But when I run the image java version is "1.7.0_111", even though it is expected to be JDK 8:

docker run -i -t <image> /bin/bash

[user@2fcc1e47c3cd projects]$ java -version

java version "1.7.0_111"
OpenJDK Runtime Environment (rhel-2.6.7.2.el7_2-x86_64 u111-b01)
OpenJDK 64-Bit Server VM (build 24.111-b01, mixed mode)

There are many sources which describe Oracle JDK installations, but I was not able to find any relevant instructions for OpenJDK

like image 257
Ilya Buziuk Avatar asked Nov 16 '16 15:11

Ilya Buziuk


2 Answers

Seems to be as easy as this:

FROM centos

RUN yum install -y \
       java-1.8.0-openjdk \
       java-1.8.0-openjdk-devel

ENV JAVA_HOME /etc/alternatives/jre
.
.
like image 106
Ilya Buziuk Avatar answered Oct 30 '22 11:10

Ilya Buziuk


When JDK for development is installed, then JAVA_HOME should point to JDK instead of JRE.

RUN yum install -y \
   java-1.8.0-openjdk \
   java-1.8.0-openjdk-devel

ENV JAVA_HOME /usr/lib/jvm/java-1.8.0-openjdk/
like image 33
MariuszS Avatar answered Oct 30 '22 10:10

MariuszS