title: Dockerfile alpine image apk cannot find Java 8
body: <p>I wanted to reduce my docker image and switched to an alpine base image instead. This lead to problems bash not finding apt. Turns out, I have to use apk instead. However, it does not seem to find the java version I need. Here is my dockerfile</p>
  
  <pre><code>#Use alpine golang
  FROM golang:alpine
  
  #Get the code from local code commit repo
  WORKDIR /go/src/xxx
  COPY . /go/src/xxx
  
  #Install Java and cleanup after in the same layer
  RUN apk update &amp;&amp; apk add openjdk-8-jre-headless &amp;&amp; rm -rf /var/lib/apt/lists/*
  
  #Install dependencies recursively and remove the third_party directory after it has been used for compiling.
  RUN go get ./... &amp;&amp; go run setup.go &amp;&amp; RUN rm -rf third_party
  #More commands...
  
  
  
   ---&gt; 32a6b6b5f196 
  Step 4/8 : RUN apk update &amp;&amp; apk add openjdk-8-jre-headless &amp;&amp; rm -rf /var/lib/apt/lists/* 
   ---&gt; Running in bc48930e48be 
  fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/main/x86_64/APKINDEX.tar.gz 
  fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/community/x86_64/APKINDEX.tar.gz 
  v3.9.4-4-gd5dd5c1cd0 [http://dl-cdn.alpinelinux.org/alpine/v3.9/main] 
  v3.9.4-5-gcfdf5452f1 [http://dl-cdn.alpinelinux.org/alpine/v3.9/community] 
  OK: 9766 distinct packages available 
    openjdk-8-jre-headless (missing): 
  ·[91mERROR: unsatisfiable constraints: 
  ·[0m    required by: world[openjdk-8-jre-headless] 
  The command '/bin/sh -c apk update &amp;&amp; apk add openjdk-8-jre-headless &amp;&amp; rm -rf /var/lib/apt/lists/*' returned a non-zero code: 1
  </code></pre>
  
  <p>I have also tried</p>
  
  <pre><code>RUN apk update &amp;&amp; apk add -t jessie-backports openjdk-8-jre-headless ca-certificates-java &amp;&amp; rm -rf /var/lib/apt/lists/*
  </code></pre>
  
  <p>According to <a href="https://unix.stackexchange.com/questions/342403/openjdk-8-jre-headless-depends-ca-certificates-java-but-it-is-not-going-to-be">https://unix.stackexchange.com/questions/342403/openjdk-8-jre-headless-depends-ca-certificates-java-but-it-is-not-going-to-be</a> but that also fails, not sure if the -t flags fault:</p>
  
  <pre><code>Step 4/7 : RUN apk update &amp;&amp; apk add -t jessie-backports openjdk-8-jre-headless ca-certificates-java &amp;&amp; rm -rf /var/lib/apt/lists/* 
   ---&gt; Running in 1e2ef22e7c16 
  fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/main/x86_64/APKINDEX.tar.gz 
  fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/community/x86_64/APKINDEX.tar.gz 
  v3.9.4-4-gd5dd5c1cd0 [http://dl-cdn.alpinelinux.org/alpine/v3.9/main] 
  v3.9.4-5-gcfdf5452f1 [http://dl-cdn.alpinelinux.org/alpine/v3.9/community] 
  OK: 9766 distinct packages available 
  ·[91mERROR: unsatisfiable constraints: 
  ·[0m  openjdk-8-jre-headless (missing): 
      required by: jessie-backports-0[openjdk-8-jre-headless] 
    ca-certificates-java (missing): 
      required by: jessie-backports-0[ca-certificates-java] 
  The command '/bin/sh -c apk update &amp;&amp; apk add -t jessie-backports openjdk-8-jre-headless ca-certificates-java &amp;&amp; rm -rf /var/lib/apt/lists/*' returned a non-zero code: 3 
  </code></pre>