Skip to content

Instantly share code, notes, and snippets.

@brunoborges
Created November 28, 2022 19:29
Show Gist options
  • Save brunoborges/8bddb05399a858f1048a49c98b6a45ac to your computer and use it in GitHub Desktop.
Save brunoborges/8bddb05399a858f1048a49c98b6a45ac to your computer and use it in GitHub Desktop.
Issue #55 in microsoft/openjdk-docker repo
import java.lang.management.ManagementFactory;
public class App {
public static void main(String[] args) {
long currentTime = System.currentTimeMillis();
long startTime = ManagementFactory.getRuntimeMXBean().getStartTime();
System.out.println("JVM Startup time: " + (currentTime - startTime));
}
}
FROM mcr.microsoft.com/openjdk/jdk:17-distroless
ADD App.class /
WORKDIR /
CMD ["App"]
FROM mcr.microsoft.com/openjdk/jdk:17-mariner
ADD App.class /
WORKDIR /
CMD ["java", "App"]
FROM mcr.microsoft.com/openjdk/jdk:17-ubuntu
ADD App.class /
WORKDIR /
CMD ["java", "App"]
$ java -version
openjdk version "17.0.5" 2022-10-18 LTS
OpenJDK Runtime Environment Microsoft-6841604 (build 17.0.5+8-LTS)
OpenJDK 64-Bit Server VM Microsoft-6841604 (build 17.0.5+8-LTS, mixed mode)
$ javac App.java
$
$ md5 App.java App.class
MD5 (App.java) = 260860c7e4ea46f2ed5b2282cfe1c722
MD5 (App.class) = c807111d3eee0e77c03896743ed059e4
$ docker version
[...]
Server: Docker Desktop 4.13.1 (90346)
[...]
$ docker run -ti mcr.microsoft.com/openjdk/jdk:17-ubuntu java -version
openjdk version "17.0.5" 2022-10-18 LTS
OpenJDK Runtime Environment Microsoft-6841604 (build 17.0.5+8-LTS)
OpenJDK 64-Bit Server VM Microsoft-6841604 (build 17.0.5+8-LTS, mixed mode, sharing)
$ docker run -ti mcr.microsoft.com/openjdk/jdk:17-distroless -version
openjdk version "17.0.5" 2022-10-18 LTS
OpenJDK Runtime Environment Microsoft-6841604 (build 17.0.5+8-LTS)
OpenJDK 64-Bit Server VM Microsoft-6841604 (build 17.0.5+8-LTS, mixed mode, sharing)
$ docker build -t test:ubuntu -f Dockerfile.ubuntu .
[...]
$ docker build -t test:distroless -f Dockerfile.distroless .
[...]
$ docker build -t test:mariner -f Dockerfile.mariner .
[...]
$ echo "17-distroless" && time docker run -ti test:distroless && echo "17-ubuntu" && time docker run -ti test:ubuntu && echo "17-mariner" && time docker run -ti test:mariner
17-distroless
JVM Startup time: 194
docker run -ti test:distroless 0.04s user 0.02s system 6% cpu 1.091 total
17-ubuntu
JVM Startup time: 159
docker run -ti test:ubuntu 0.04s user 0.02s system 5% cpu 1.070 total
17-mariner
JVM Startup time: 203
docker run -ti test:mariner 0.05s user 0.02s system 6% cpu 1.156 total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment