phanteh phanteh - 11 months ago 81
Java Question

Docker alpine + oracle java: cannot find java

I've been trying to create an alpine-based docker image with Oracle Java (rather than openjdk). I have been specifically asked to create our own image here.

This is the Dockerfile I've come up with:

FROM alpine:3.6

RUN apk add --no-cache curl wget

RUN mkdir /opt/ && \
wget -c --header "Cookie: oraclelicense=accept-securebackup-cookie"\ && \
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

There are some unnecessary commands (like echoing the JAVA_HOME dir) which were added to help with debugging, but now I'm stuck:
RUN which java
as expected, but
RUN java -version
/bin/sh: java: not found

I've tried a few things, including symlinking the executable(s) into /usr/bin, to no avail.

What am I missing?

Final output from docker is:
The command '/bin/sh -c java -version' returned a non-zero code: 127

Final edit:

Thanks to diginoise for putting me on to MUSL vs libc. I found adding the following to my Dockerfile allowed me to build a working image:

RUN apk --no-cache add ca-certificates && \
wget -q -O /etc/apk/keys/ && \
wget && \
apk add glibc-2.25-r0.apk

Found at:

Answer Source

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).

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

See this link

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

In short use official Oracle Java Docker image

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download