title: Docker alpine + oracle java: cannot find java
body: <p>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. </p>
  
  <p>This is the Dockerfile I've come up with:</p>
  
  <pre><code>FROM alpine:3.6
  
  RUN apk add --no-cache curl wget
  
  RUN mkdir /opt/ &amp;&amp; \
      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 &amp;&amp; \
      tar xvf jdk-8u131-linux-x64.tar.gz -C /opt/ &amp;&amp; \
      rm jdk-8u131-linux-x64.tar.gz &amp;&amp; \
      ln -s /opt/jdk1.8.0_131 /opt/jdk
  
  ENV JAVA_HOME /opt/jdk
  ENV PATH $PATH:/opt/jdk/bin
  
  RUN echo $JAVA_HOME &amp;&amp; \
      echo $PATH
  
  RUN which java
  RUN java -version
  </code></pre>
  
  <p>There are some unnecessary commands (like echoing the JAVA_HOME dir) which were added to help with debugging, but now I'm stuck: <code>RUN which java</code> returns <code>/opt/jdk/bin/java</code> as expected, but <code>RUN java -version</code> returns <code>/bin/sh: java: not found</code>.</p>
  
  <p>I've tried a few things, including symlinking the executable(s) into /usr/bin, to no avail.</p>
  
  <p>What am I missing?</p>
  
  <p>EDIT:
  Final output from docker is:
  <code>The command '/bin/sh -c java -version' returned a non-zero code: 127</code></p>
  
  <p>Final edit:</p>
  
  <p>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:</p>
  
  <pre><code>RUN apk --no-cache add ca-certificates &amp;&amp; \
  wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://raw.githubusercontent.com/sgerrand/alpine-pkg-glibc/master/sgerrand.rsa.pub &amp;&amp; \
  wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.25-r0/glibc-2.25-r0.apk &amp;&amp; \
  apk add glibc-2.25-r0.apk
  </code></pre>
  
  <p>Found at: <a href="https://github.com/sgerrand/alpine-pkg-glibc" rel="noreferrer">https://github.com/sgerrand/alpine-pkg-glibc</a></p>