Skip to content

Instantly share code, notes, and snippets.

@richmidwinter
Last active January 13, 2020 14:36
Show Gist options
  • Save richmidwinter/b2e3498397360f65afc3db55f48e5d6c to your computer and use it in GitHub Desktop.
Save richmidwinter/b2e3498397360f65afc3db55f48e5d6c to your computer and use it in GitHub Desktop.
Slim JDK container on Alpine Linux with non-root user
FROM azul/zulu-openjdk-alpine:11 AS builder
WORKDIR /
RUN /usr/lib/jvm/default-jvm/bin/jlink --no-header-files --no-man-pages --compress=2 --strip-debug --add-modules java.base,java.compiler,java.desktop,java.instrument,java.logging,java.management,java.naming,java.scripting,java.security.jgss,java.sql,java.xml,jdk.attach,jdk.jdi,jdk.management,jdk.unsupported,jdk.crypto.ec --output /build/jre
FROM alpine
COPY --from=builder /build/jre /usr/local/java
COPY ld-musl-x86_64.path /etc/ld-musl-x86_64.path
RUN apk add --no-cache libcap
RUN adduser -S java
RUN ln -sf /usr/local/java/bin/java /usr/bin/java
RUN setcap 'cap_net_bind_service=+ep' /usr/local/java/bin/java
/lib
/usr/lib
/usr/local/java/lib
/usr/local/java/lib/server
/usr/local/java/lib/security
/usr/local/java/lib/jli
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment