Skip to content

Instantly share code, notes, and snippets.

@up1
Last active April 25, 2024 06:42
Show Gist options
  • Save up1/18eef18e0a50cebd91bf69fefea603b0 to your computer and use it in GitHub Desktop.
Save up1/18eef18e0a50cebd91bf69fefea603b0 to your computer and use it in GitHub Desktop.
Docker + OpenJDK
$docker image build -t v2 .
$docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
v2 latest be1d4e472288 12 minutes ago 94.4MB
v1 latest ea33af4a5e61 18 minutes ago 741MB
$dive v2
┃ ● Layers ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ├── bin
Cmp Size Command │ ├── arch → /bin/busybox
7.4 MB FROM blobs │ ├── ash → /bin/busybox
87 MB COPY /custom-runtime /opt/jdk # buildkit │ ├── base64 → /bin/busybox
│ ├── bbconfig → /bin/busybox
│ ├── busybox
│ ├── cat → /bin/busybox
│ ├── chattr → /bin/busybox
│ ├── chgrp → /bin/busybox
│ Layer Details ├────────────────────────────────────── │ ├── chmod → /bin/busybox
│ ├── chown → /bin/busybox
Tags: (unavailable) │ ├── cp → /bin/busybox
Id: blobs │ ├── date → /bin/busybox
Digest: sha256:d4fc045c9e3a848011de66f34b81f052d4f2c15a │ ├── dd → /bin/busybox
17bb196d637e526349601820 │ ├── df → /bin/busybox
Command: │ ├── dmesg → /bin/busybox
#(nop) ADD file:37a76ec18f9887751cd8473744917d08b7431fc │ ├── dnsdomainname → /bin/busybox
│ ├── dumpkmap → /bin/busybox
│ Image Details ├────────────────────────────────────── │ ├── echo → /bin/busybox
│ ├── egrep → /bin/busybox
Image name: v2 │ ├── false → /bin/busybox
Total Image size: 94 MB │ ├── fatattr → /bin/busybox
Potential wasted space: 0 B │ ├── fdflush → /bin/busybox
Image efficiency score: 100 % │ ├── fgrep → /bin/busybox
│ ├── fsync → /bin/busybox
Count Total Space Path │ ├── getopt → /bin/busybox
│ ├── grep → /bin/busybox
│ ├── gunzip → /bin/busybox
▏^C Quit ▏Tab Switch view ▏^F Filter ▏^L Show layer changes ▏^A Show aggregated changes ▏
FROM alpine:latest AS build
ENV JAVA_HOME /opt/jdk/jdk-21.0.1
ENV PATH $JAVA_HOME/bin:$PATH
ADD https://download.bell-sw.com/java/21.0.1+12/bellsoft-jdk21.0.1+12-linux-x64-musl.tar.gz /opt/jdk/
RUN tar -xzvf /opt/jdk/bellsoft-jdk21.0.1+12-linux-x64-musl.tar.gz -C /opt/jdk/
RUN ["jlink", "--compress=2", \
"--module-path", "/opt/jdk/jdk-21.0.1/jmods/", \
"--add-modules", "java.base,java.logging,java.naming,java.desktop,jdk.unsupported", \
"--no-header-files", "--no-man-pages", \
"--output", "/custom-runtime"]
FROM alpine:latest
COPY --from=build /custom-runtime /opt/jdk
ENV PATH=$PATH:/opt/jdk/bin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment