Skip to content

Instantly share code, notes, and snippets.

@rhuss
Last active January 3, 2021 13:03
Show Gist options
  • Save rhuss/6d3c0c687fb4ec39c3e4 to your computer and use it in GitHub Desktop.
Save rhuss/6d3c0c687fb4ec39c3e4 to your computer and use it in GitHub Desktop.
The Holy Grail of a Minimal, Headless, OpenJDK JRE 8
# Build for 206 MB JRE 1.8.0_60 (192 MB in size) with Alping and glibc
FROM alpine:3.2
ENV JRE=jre1.8.0_60 \
JAVA_HOME=/opt/jre
# That's the an EA from OpenJDK.net
# Courtesy to https://github.com/frol/docker-alpine-oraclejdk8 from where the setup of glibc is borrowed
RUN apk add --update wget ca-certificates && \
cd /tmp && \
wget "https://circle-artifacts.com/gh/andyshinn/alpine-pkg-glibc/6/artifacts/0/home/ubuntu/alpine-pkg-glibc/packages/x86_64/glibc-2.21-r2.apk" \
"https://circle-artifacts.com/gh/andyshinn/alpine-pkg-glibc/6/artifacts/0/home/ubuntu/alpine-pkg-glibc/packages/x86_64/glibc-bin-2.21-r2.apk" && \
apk add --allow-untrusted glibc-2.21-r2.apk glibc-bin-2.21-r2.apk && \
/usr/glibc/usr/bin/ldconfig /lib /usr/glibc/usr/lib && \
echo 'hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4' >> /etc/nsswitch.conf && \
mkdir /opt && \
wget http://www.java.net/download/jdk8u60/archive/b18/binaries/jre-8u60-ea-bin-b18-linux-x64-02_jun_2015.tar.gz -O /tmp/${JRE}.tgz && \
cd /opt && tar zxvf /tmp/${JRE}.tgz && \
ln -s /opt/${JRE} /opt/jre && \
ln -s /opt/jre/bin/java /usr/bin/java && \
apk del wget ca-certificates && \
cd /opt/jre/lib/amd64 && rm libjavafx_* libjfx* libfx* && \
cd /opt/jre/lib/ && rm -rf ext/jfxrt.jar jfxswt.jar javafx.properties font* && \
rm /tmp/* /var/cache/apk/*
@rhuss
Copy link
Author

rhuss commented Jun 6, 2015

Looks like that Alpine + Glibc only adds 14 MB of overhead. Now the search for a minimal JRE-8 with

  • full functionality
  • headless
  • no fluff

has started.

@rhuss
Copy link
Author

rhuss commented Jun 6, 2015

If somebody knows where I can download a .tar of a headless OpenJDK JRE-8, preferred with wget or curl, that would be super awesome.

@rhuss
Copy link
Author

rhuss commented Jun 6, 2015

Yep, got a JDK image with 187 MB with this Dockerfile:

#187 MB JDK image on Alpine + glibc
FROM alpine:3.2

ENV JAVA_HOME=/opt/jdk

# This one is from http://www.linuxfromscratch.org/blfs/view/svn/general/java.html
ADD jdk1.8.0_45.gz /opt

RUN apk add --update wget ca-certificates && \
    cd /tmp && \
    wget "https://circle-artifacts.com/gh/andyshinn/alpine-pkg-glibc/6/artifacts/0/home/ubuntu/alpine-pkg-glibc/packages/x86_64/glibc-2.21-r2.apk" \
         "https://circle-artifacts.com/gh/andyshinn/alpine-pkg-glibc/6/artifacts/0/home/ubuntu/alpine-pkg-glibc/packages/x86_64/glibc-bin-2.21-r2.apk" && \
    apk add --allow-untrusted glibc-2.21-r2.apk glibc-bin-2.21-r2.apk && \
    /usr/glibc/usr/bin/ldconfig /lib /usr/glibc/usr/lib && \
    echo 'hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4' >> /etc/nsswitch.conf && \
    ln -s /opt/OpenJDK-1.8.0.45-bin /opt/jdk && \
    ln -s /opt/jdk/bin/java /usr/bin/java && \
    apk del wget ca-certificates && \
    rm /tmp/* /var/cache/apk/* && \
    rm -rf /opt/jdk/demo /opt/jdk/sample /opt/jdk/man /opt/jdk/src.zip

We are getting closer ;-)

@rhuss
Copy link
Author

rhuss commented Jun 7, 2015

A further optimization of the official build is to avoid the initial ADD and do a direct download, extraction, removal in one single RUN step to avoid the large layer added qith ADD

Also removing JavaFX helps quite a bit.

Image size is now down to 127 MB

@rhuss
Copy link
Author

rhuss commented Jun 7, 2015

@atomi
Copy link

atomi commented Sep 23, 2015

Is there an ARMV6 or ARMV7 of glibc for alpine?

@flyinprogrammer
Copy link

So I'm going to go do some research but maybe someone here knows already?
There seems to be already maintained openjdk packages in the apk repos: https://pkgs.alpinelinux.org/package/community/x86_64/openjdk8

And it requires musl instead of a glibc package -- is it documented anywhere that openjdk and/or oracle jdk require glibc? or one requires one vs the other?

@jokester
Copy link

Oracle JDK is not working with musl, see this issue.
Alpine's OpenJDK build seems to be fine with musl (and w/o glibc), I'm running a artifactory instance with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment