20
REPOSITORY          TAG       IMAGE ID       CREATED             SIZE
an-image            1         X              26 seconds ago      279 MB

when the docker image will be run, the following message is shown:

No java installations was detected.
Please go to http://www.java.com/getjava/ and download

When Oracle JDK is deployed the docker image size is more than doubled!

REPOSITORY          TAG       IMAGE ID       CREATED             SIZE
an-image            2         X              26 seconds ago      666 MB

Discussion

When "Is there no Oracle JDK for docker" is googled only some links to docker image that contain docker are returned. When Oracle JDK is deployed in the docker image the size is more than doubled. I want to keep the docker images as small as possible, but the Oracle JDK seems to be larger than the image itself!

Question

Is there no Oracle JDK for docker?

1
  • @peter feel free to jump in chatops if you want to discuss it :)
    – Tensibai
    Sep 13, 2018 at 12:35

3 Answers 3

23

No. Because you cannot distribute Oracle JDK or JRE, the license in effect doesn't allow distribution. When distributed by a third party (embedded with your app) all the liability for it not working is on that party. This is why you will not find Oracle JDK/JRE on any of the public Docker registries, or in any Linux package repositories for that matter.

You can create your own image, and install Oracle JDK or JRE using the webupd8team/java package for Ubuntu/Debian.

And if you are using Alpine Linux this blog post explains which dependencies are required, and links to StackOverflow for installation instructions.

Update: Oracle has an official Docker image on the Docker Store now. https://blogs.oracle.com/developers/official-docker-image-for-oracle-java-and-the-openjdk-roadmap-for-containers

Link to Docker Store Oracle Java Image - https://store.docker.com/images/oracle-serverjre-8

6
  • 1
    hub.docker.com/r/anapsix/alpine-java
    – 030
    Mar 8, 2017 at 13:40
  • I wouldn't rely on it being available for long. As I wrote, the license from Oracle does not allow to publicly distribute it - only Oracle can legaly distribute their JDK or JRE. So basically, this repository is illegal and will most likely disappear. Mar 8, 2017 at 13:41
  • What you can do, is use their Dockerfiles on GitHub to get your own Docker image with Java. For example github.com/anapsix/docker-alpine-java/blob/master/8/121b13/jdk/… Mar 8, 2017 at 13:43
  • And once the docker image is created I am allowed to store it in our private docker registry?
    – 030
    Mar 8, 2017 at 13:44
  • 1
    Yes. The license prohibits from publicly distributing the JDK/JRE in binary form. Mar 8, 2017 at 13:44
8

As docker is not an operating system, no there's no JDK for docker.

As I understand your question, it's that a full JDK is too large for your wishes, in this case you may try switching to just the JRE and include only necessary libraries.

JDK is the acronym of Java Development Kit, JRE is the one for Java Runtime Engine. By "lazyness" due to the complexity to list every needed dependency no one strip down to the necessary libraries only, but that is the way to go if you wish to reduce the installed size to strict minimum.

A more usable way could be strip off some of the installed things which are taking a lot of space:

/usr/lib/jvm/jdk1.8.0_101$ du -hs *
776K    bin
4.0K    COPYRIGHT
5.7M    db
208K    include
4.9M    javafx-src.zip
187M    jre
133M    lib
4.0K    LICENSE
2.0M    man
4.0K    README.html
4.0K    release
21M     src.zip
108K    THIRDPARTYLICENSEREADME-JAVAFX.txt
176K    THIRDPARTYLICENSEREADME.txt

There's two *src.zip which can be removed, they won't be of use, and as you can see the lib directory is half the size and within it you have a bunch of things you don't really need:

/usr/lib/jvm/jdk1.8.0_101$ du -hs lib/*
120K    lib/amd64
1.2M    lib/ant-javafx.jar
18M     lib/ct.sym
160K    lib/dt.jar
20K     lib/ir.idl
36K     lib/javafx-mx.jar
400K    lib/jconsole.jar
12K     lib/jexec
60M     lib/missioncontrol
4.0K    lib/orb.idl
8.0K    lib/packager.jar
2.4M    lib/sa-jdi.jar
18M     lib/tools.jar
34M     lib/visualvm

You can without problem remove missoncontrol on a server, I assume you can get rid of visualvm also, you'll have to check if you need something in this lib directory, but I can't tell without knowing your app..

One thing you should do in your dockerfile while installing oracle jdk is to remove the downloaded .tar.gz file which is roughly the same size as the resulting directory as .jar files are already compressed, the tar.gz is just there to "package" them.

You have to do all this in the same RUN command, chaining with && to avoid adding layers where you won't remove size by removing files from previous layer.

3

There is no official Oracle JDK implementation provided by Docker. Docker used to support their own Java library on hub.docker.com, but they deprecated it in favor of the actual OpenJDK implementation since it was "OpenJDK-specific since it was first introduced". Their reasoning:

As all of the major upstream Linux distributions are unwilling to redistribute Oracle Java in their own distribution channels, we have chosen to follow them. See references below on how each distribution does not distribute Oracle Java.

So if you want to keep your Docker image as small as possible, consider using OpenJDK instead. There's an official OpenJDK Dockerfile repository or you can just use docker pull openjdk. The basic "easy to run" Dockerfile for OpenJDK 7 is as follows (taken from the website listed in the previous sentence):

FROM openjdk:7
COPY . /usr/src/myapp
WORKDIR /usr/src/myapp
RUN javac Main.java
CMD ["java", "Main"]
3
  • 1
    There is no official Oracle JDK? That seems somewhat incorrect, or at least phrased incorrectly. Mar 8, 2017 at 13:38
  • 1
    @Evgeny I agree, I assume the intent is to say: "No official docker image including Oracle JDK from Oracle", maybe just a "docker " missing between JDK and implementation...
    – Tensibai
    Mar 8, 2017 at 13:59
  • Oops, yes I did mean to make that Docker specific. I have corrected my answer.
    – Peter G
    Mar 8, 2017 at 19:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.