Docker alpine + oracle java: cannot find java

I found an answer that works finally. All is needed is just the GlibC; huge thanks to S. Gerrand, this is such a big help.

Here's how to get the old JDK 8 running in Alpine 1.13:

FROM alpine:3.13

RUN apk --no-progress --purge --no-cache upgrade \
&& apk --no-progress --purge --no-cache add --upgrade \
    curl \
    wget \
    openssh \
&& apk --no-progress --purge --no-cache upgrade \
&& rm -vrf /var/cache/apk/* \
&& curl --version

# Install vanilla GLibC: https://github.com/sgerrand/alpine-pkg-glibc
RUN curl -o /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \
&& curl -LO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.32-r0/glibc-2.32-r0.apk \
&& apk add glibc-2.32-r0.apk

RUN wget -c --header "Cookie: oraclelicense=accept-securebackup-cookie" \
        http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz \
  && tar xvf jdk-8u131-linux-x64.tar.gz -C /opt \
  && rm jdk-8u131-linux-x64.tar.gz \
  && ln -s /opt/jdk1.8.0_131 /opt/jdk

ENV JAVA_HOME /opt/jdk
ENV PATH $PATH:/opt/jdk/bin

RUN echo $JAVA_HOME && \
    echo $PATH

RUN which java
RUN java -version

ENTRYPOINT [ "java" ]

# To test run: docker run -t khalifahks/alpine-java -version
# docker export <container-id> | docker import - khalifahks/alpine-java:exported
# quick interative termnal: docker run -it --entrypoint=sh khalifahks/alpine-java sh

You cannot achieve what you want

Alpine Linux uses MUSL as a Standard C library.

Oracle's Java for linux depends on GNU Standard C library (gclib).

Here is a bit more detailed info and official stance from Oracle on the topic

the JDK source code has not yet been ported to Alpine Linux, or more specifically, the musl C library. That is, it turns out that the thing about Alpine Linux that sticks out/is different from a JDK source code perspective is the C library.

The solution

If you looking for small Java Docker images, use OpenJDK ones.

openjdk:11-jre-slim image is only 77MB.


If you insist, on your head be it...

There is theoretical way, but it is not as trivial as you think.

You can find many examples of Alpine images running with OracleJDK like here or see expert's answer to this question as well. They add the missing Standard GNU C library.

Be warned however...

All of these solutions could be in breach of Oracle's license agreement stating that the license is non-transferable, and the distributable is non-modifiable. In the Dockerfiles you will find however:

Cookie: oraclelicense=accept-securebackup-cookie"

and many entries similar to

rm -rf ${JAVA_HOME}/*src.zip

For further details about legality of prepackaged Oracle's JRE or JDK Docker images see this article.