Deprecation of OpenJDK Docker Images and the Importance of Switching to Secure Alternatives

If you're using openjdk Docker images as a base image for your projects, then it's time to take a closer look.

Posted by on

If you're using OpenJDK Docker images as a base image for your projects, then it's time to take a closer look. These images have been deprecated and are no longer receiving security updates. This means that any projects that use them are now at risk of security bugs.

The Implications of OpenJDK Docker Images Deprecation

Docker images are a popular way to package applications and their dependencies, and OpenJDK images are a common base image for Java applications. The images are built on top of an operating system and include the Java Runtime Environment (JRE) or Java Development Kit (JDK).

However, the deprecation of these OpenJDK images means that they will no longer receive security updates. This puts any applications built on them at risk of security vulnerabilities. Since Java is often used for web applications, the potential consequences of these vulnerabilities can be severe. For example, they can lead to data breaches, unauthorised access to sensitive information, and even complete system compromise.

The Importance of Switching to Secure Alternatives

To ensure the security of your applications, it's important to switch to a secure alternative. Two popular options are the Eclipse Adoptium project's Temurin image and Amazon Corretto image. Both of these images are built on top of the OpenJDK and are actively maintained with regular security updates.

How to Switch to Secure Alternatives

Switching to a secure alternative like Eclipse Adoptium project's Temurin image or Amazon Corretto image is a relatively straightforward process. Here are the steps you need to follow:

Step 1: Determine which alternative to use

Both Temurin and Corretto are secure alternatives to the deprecated openjdk images. However, you should consider the specific requirements of your application to determine which one is best for your needs. Factors to consider include compatibility, licensing, and support.

Step 2: Update your Dockerfile

Once you've chosen your new base image, you'll need to update your Dockerfile to reflect the change. Replace the deprecated OpenJDK image with your chosen alternative, and make any other necessary changes to your Dockerfile.

Step 3: Test your application

After updating your Dockerfile, you should test your application to ensure that it works as expected. This will help you identify any compatibility issues that may arise due to the change in base image.

Step 4: Deploy your updated application

Once you've tested your application and resolved any issues, you can deploy your updated application with the new base image.

Key Considerations When Switching to Secure Alternatives

When switching to a new base image, there are several key considerations you need to make to ensure compatibility and avoid potential issues. Here are a few things to keep in mind:

Compatibility with Your Application

Make sure that the new base image is compatible with your application. This includes ensuring that any required libraries and dependencies are present in the new image.

Licensing

Be aware of the licensing requirements of your chosen alternative. Some images may have restrictions on commercial use or redistribution.

Support

Consider the level of support available for the new base image. Ensure that there is an active community or support team to help you resolve any issues that may arise.

Security

Make sure that the new base image is actively maintained and receiving regular security updates.

Creating Custom JREs with jlink

In the past, Docker provided JRE images for Java applications. However, with the deprecation of openjdk Docker images, JRE images are no longer provided. Instead, it is recommended to use JDK images or create custom JREs using jlink.

Jlink is a tool that allows you to create a custom JRE that includes only the necessary modules for your application. This helps to reduce the size of the image and improve security by removing unnecessary components.

Here's an example of how to create a custom JRE from a base image like Temurin:

# Use Temurin's OpenJDK 11 as base image
FROM eclipse-temurin:11 as jre-builder

# Install necessary tools for jlink
RUN apt-get update && apt-get install -y wget ca-certificates zip unzip

# Use jlink to create a custom JRE
RUN jlink --compress=2 --strip-debug --no-header-files --no-man-pages \
          --add-modules java.base,java.logging,java.xml \
          --output /opt/jre

# Use a base image for your application
FROM debian:buster-slim

# Copy the custom JRE from previous build stage
COPY --from=jre-builder /opt/jre /opt/jre

# Set PATH to use the custom JRE
ENV PATH="/opt/jre/bin:${PATH}"

# Set working directory
WORKDIR /app

# Copy application JAR file to container
COPY myapp.jar .

# Start application
CMD ["java", "-jar", "myapp.jar"]

In this example, we start with Temurin's OpenJDK 11 as the base image and use jlink to create a custom JRE that includes only the necessary modules for our application. We then use the custom JRE as the base image for our application and set the PATH to use the custom JRE. Finally, we copy the application JAR file to the container and start the application.

By creating custom JREs with jlink, we can optimise the size and security of our Docker images while still providing the necessary components for our Java applications.

Conclusion

In conclusion, the deprecation of OpenJDK Docker images highlights the importance of regularly reviewing and updating your software dependencies to ensure they remain secure. By switching to secure alternatives like Eclipse Adoptium project's Temurin image or Amazon Corretto image, you can ensure that your Java applications are protected against security vulnerabilities.

When making the switch, it's important to follow best practices and take the necessary steps to ensure compatibility with your application. This includes choosing the right alternative, updating your Dockerfile, testing your application, and deploying your updated application.

By taking these steps, you can protect your applications from security risks and ensure that they remain secure and stable. As always, if you have any questions or need assistance with updating your Docker images, don't hesitate to reach out to Kedos Consulting for help.