1. Overview

Docker is a containerization platform that helps developers to bundle their applications into a single unit known as a container. OpenJDK is a free, community-maintained version of the Java Development Kit (JDK). Docker images for OpenJDK are pre-configured environments that include the OpenJDK runtime and tools.

Selecting the right OpenJDK Docker image is critical since it can impact the performance, size, and security of our software. Different images come with different compromises, such as the size of the image or its speed. Therefore, it’s vital to understand the differences between OpenJDK Docker images to come to a conclusive decision.

In this tutorial, we’ll learn about the difference between various Docker images of OpenJDK.

Note: As of July 2022, Docker Hub deprecated OpenJDK images. Users are recommended to use suitable replacements such as Amazon Corretto, and Eclipse Temurin.

2. Understanding the Differences

The main differences between these images lie in the base operating system, integrated packages, and overall image size. Slim and Slim-Stretch are based on Debian Linux, whereas Stretch is based on the full “stretch” release of Debian. On the other hand, Alpine uses the Alpine Linux distribution, recognized for its compact size and security measures.

Among the smallest and largest images, Slim is the smallest, while Stretch is the largest. Alpine is also a small image, but it is based on a different Linux distribution. The performance of different images varies depending on the workload and use case. The Slim and Alpine images are generally faster and use fewer resources than the larger images. However, larger images may be necessary for applications requiring more dependencies. The Alpine image has a large and active community that supports and updates the image, whereas the Slim and Stretch images may have a smaller community.

3. Slim

The Slim image is the smallest OpenJDK Docker image available, its size for the Java 8 version is around 295MB. It is optimized for production use and includes only the minimum packages required to run Java applications. Let’s take a look at the command to pull the Java 8 version of the OpenJDK slim image:

$ docker pull openjdk:8-jdk-slim
8-jdk-slim: Pulling from library/openjdk
1efc276f4ff9: Pull complete 
a2f2f93da482: Pull complete 
1a2de4cc9431: Pull complete 
9013b84ebbe7: Pull complete 
Digest: sha256:19578a1e13b7a1e4cab9b227fb7b5d80e14665cf4024c6407d72ba89842a97ed
Status: Downloaded newer image for openjdk:8-jdk-slim

The Slim image is a good choice for applications that require a small image size and fast startup time, such as microservices and serverless functions. Let’s check out the image size of openjdkL8-jdk-slim:

$ docker images openjdk:8-jdk-slim
openjdk      8-jdk-slim   80e75f92be33   7 months ago   295MB

The main advantage of using the Slim image is its small size and fast startup time. This package only includes the components we need to run Java applications without containing any extraneous packages. Applications that require fewer dependencies would benefit from this image. Due to the minimal package set, it might not be suitable for all applications.

4. Slim-Stretch

The Slim-Stretch image is a sensible pick for software that demands a small image size but requires additional software from the Debian “stretch” release. This may involve software that requires tools or libraries that aren’t part of the previous Debian releases. For instance, libfontconfig1 is not available in the Slim image, whereas Slim-Stretch includes additional tools and libraries from the Debian stretch release, including libfontconfig1.

The key benefit of utilizing Slim-Stretch is that it has additional packages that were not shipped in previous Debian releases, yet at the same time inherits the small footprint of Slim image. The downside is that Slim-Stretch may not be as fine-tuned for production use. Let’s take a look at the command to pull the Java 8 version of the openjdk:8-jdk-slim-stretch image:

$ docker pull openjdk:8-jdk-slim-stretch
8-jdk-slim-stretch: Pulling from library/openjdk
fc7181108d40: Pull complete 
73f08ce352c8: Pull complete 
eac271a34b40: Pull complete 
774220066612: Pull complete 
Digest: sha256:9fa43d5e1c45e42c0dbbf3713d49edd8e7cc01be9e1c4ef5e723efd6dfb47929
Status: Downloaded newer image for openjdk:8-jdk-slim-stretch

Let’s check out the image size of openjdk:8-jdk-slim-stretch:

$ docker images openjdk:8-jdk-slim-stretch
REPOSITORY   TAG                  IMAGE ID       CREATED       SIZE
openjdk      8-jdk-slim-stretch   4de02be2e9ab   3 years ago   269MB

The Slim-Stretch image is a lot similar to the Slim image but comes with an extra package from the Debian “stretch” release.

5. Stretch

The Stretch image is the heaviest among the Slim, Slim-Stretch and Strech images. It has a more extensive range of packages and dependencies than other images, making it a fitting option for some applications. There is libgtk-3-dev in Stretch that provides GTK+ version 3 but it’s not present in Slim or Slim-Stretch. Some applications with a graphical user interface require this library, which may not be included in smaller images.

The primary benefit of utilizing Stretch is its comprehensive range of packages and dependencies, which can be critical for specific applications. However, it is significantly larger than the other images and may not be as optimized for production purposes. Let’s take a look at the command to pull the Java 8 version of the openjdk:8-jdk-stretch image:

$ docker pull openjdk:8-jdk-stretch
8-jdk-stretch: Pulling from library/openjdk
3192219afd04: Pull complete 
17c160265e75: Pull complete 
cc4fe40d0e61: Pull complete 
9d647f502a07: Pull complete 
d108b8c498aa: Pull complete 
1bfe918b8aa5: Pull complete 
dafa1a7c0751: Pull complete 
Digest: sha256:d8d62fe0d8e9f3e6e62921c7d738c9a962efd6887b2b282dc2f852d7f1ee4512
Status: Downloaded newer image for openjdk:8-jdk-stretch

Let’s check out the image size of openjdk:8-jdk-stretch:

$ docker images openjdk:8-jdk-stretch
REPOSITORY   TAG             IMAGE ID       CREATED       SIZE
openjdk      8-jdk-stretch   0bfcee65c8ca   3 years ago   488MB

The Stretch image is a practical selection for applications requiring a broad range of packages and dependencies, particularly those that need specific libraries or tools absent in the smaller images.

6. Alpine

The Alpine image relies on the Alpine Linux operating system, which is famous for its compact size and security features. It is the most compact OpenJDK Docker image accessible.

The main benefits of utilizing Alpine are its diminutive size and robust security features. However, it may not fit all software applications since it has a different package manager and may not incorporate all the packages required by some applications. Let’s take a look at the command to pull the Java 8 version of the openjdk:8-jdk-alpine image:

$ docker pull openjdk:8-jdk-alpine
8-jdk-alpine: Pulling from library/openjdk
e7c96db7181b: Pull complete 
f910a506b6cb: Pull complete 
c2274a1a0e27: Pull complete 
Digest: sha256:94792824df2df33402f201713f932b58cb9de94a0cd524164a0f2283343547b3
Status: Downloaded newer image for openjdk:8-jdk-alpine

Let’s check out the image size of openjdk:8-jdk-alpine:

$ docker images openjdk:8-jdk-alpine
openjdk      8-jdk-alpine   a3562aa0b991   3 years ago   105MB

The Alpine image is a smart pick for applications that require a small image size and secure settings, like those that operate in a containerized or cloud-native environment.

7. Choosing the Right OpenJDK Image

Selecting the right OpenJDK Docker image for our needs is a vital decision that can impact our application’s performance, size, stability, and security. By understanding the differences between the available images and considering factors such as image size, performance requirements, and dependencies. Consequently, we can optimize the performance of our application.

When choosing an OpenJDK Docker image, it is important to consider factors such as the image’s size, our application’s performance requirements, and the specific dependencies required by our application. Best practices for selecting the ideal OpenJDK Docker image start with the smallest image that fulfils our requirements. Also, we can experiment with various images to identify the most optimal performance and regularly update our images with security patches.

8. Conclusion

In this article, we learned about the differences between various Docker images of OpenJDK. Slim is the smallest image optimized for production use. Slim-Stretch includes additional packages from the Debian “stretch” release. The Stretch includes a larger set of packages and dependencies, and Alpine is the smallest image based on the Alpine Linux distribution with strong security features.

Notify of
Inline Feedbacks
View all comments