Skip to content

Java 17 Docker Images

Problem Statement

When migrating from Java 11 to Java 17 in Docker-based microservices, developers face a significant challenge: the familiar openjdk:11-jre-slim base image (approximately 75MB) doesn't have a direct equivalent in Java 17. The OpenJDK project has deprecated its official Docker images for JDK 17, leaving developers needing to find secure, lightweight alternatives from other JDK providers.

Solution Landscape

Deprecation Notice

The official OpenJDK Docker images for Java 17 are deprecated and no longer maintained. Using openjdk:17-* images may expose you to security vulnerabilities as they contain outdated JDK 17 builds.

Several reputable vendors provide well-maintained Java 17 Docker images with different Linux bases and size characteristics.

dockerfile
FROM amazoncorretto:17.0.7-alpine

# Add user and configure working directory
ARG APPLICATION_USER=appuser
RUN adduser --no-create-home -u 1000 -D $APPLICATION_USER

RUN mkdir /app && \
    chown -R $APPLICATION_USER /app

USER 1000

COPY --chown=1000:1000 ./app.jar /app/app.jar
WORKDIR /app

EXPOSE 8080
ENTRYPOINT [ "java", "-jar", "/app/app.jar" ]
dockerfile
FROM eclipse-temurin:17-jre-alpine

COPY app.jar /app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/app.jar"]
dockerfile
FROM bellsoft/liberica-openjdk-alpine:17

COPY app.jar /app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/app.jar"]

Other Viable Options

For those not requiring Alpine Linux, consider these alternatives:

  • Eclipse Temurin with Ubuntu: eclipse-temurin:17-jre-focal
  • Eclipse Temurin with CentOS: eclipse-temurin:17-jre-centos7
  • Amazon Corretto: Various Linux distributions available
  • Oracle JDK: openjdk:17-oracle (Oracle Linux base)

Size Comparison

Different image options vary significantly in size:

Image Size Estimates
  • Alpine-based images: ~50-80MB (compressed)
  • Ubuntu/CentOS-based images: ~150-250MB
  • Oracle Linux images: ~200-300MB
  • Full JDK images: Larger than JRE-only equivalents

Best Practices

  1. Use JRE instead of JDK for production deployments when possible
  2. Choose Alpine Linux for minimal image size when compatible with your dependencies
  3. Specify exact versions to ensure reproducible builds and avoid unexpected updates
  4. Run as non-root user for enhanced security
  5. Use multi-stage builds to keep production images lean

Vendor Recommendations

  • Eclipse Temurin: Recommended by Docker's official documentation
  • Amazon Corretto: Well-maintained with Alpine support
  • Liberica JDK: Specifically optimized for microservices, recommended by Spring
  • Oracle JDK: Free for production use with Oracle Linux base

Migration Example

If you were previously using:

dockerfile
FROM openjdk:11-jre-slim

A suitable Java 17 replacement would be:

dockerfile
FROM eclipse-temurin:17-jre-alpine

This maintains similar lightweight characteristics while providing an up-to-date, secure Java 17 runtime environment.