Getting Started with Amazon Corretto 21 on Docker Images
This topic describes how to build and launch a Docker image that uses Amazon Corretto 21. You must have the latest version of Docker installed.
Using the official image for Amazon Corretto 21.
Amazon Corretto 21 is available as an official image on Docker Hub
Example
docker run amazoncorretto:21 java -version
Output:
Example
openjdk version "21.0.10" 2026-01-20 LTS OpenJDK Runtime Environment Corretto-21.0.10.7.1 (build 21.0.10+7-LTS) OpenJDK 64-Bit Server VM Corretto-21.0.10.7.1 (build 21.0.10+7-LTS, mixed mode, sharing)
Using the Corretto ECR Instance
To use the Corretto ECR instance, run the following commands:
Example
docker pull public.ecr.aws/amazoncorretto/amazoncorretto:21 docker run -it public.ecr.aws/amazoncorretto/amazoncorretto:21 /bin/bash
You can see the list of available images by going here
Amazon Corretto on Alpine
Amazon Corretto on Alpine Linux images are available on
Amazon ECR Public Gallery
Using dockerhub
Example
docker pull amazoncorretto:21-alpine-jdk docker run -it amazoncorretto:21-alpine-jdk /bin/sh
Build a Docker Image with Amazon Corretto 21
Run the following command to build an image that uses Amazon Corretto 21.
Example
docker build -t amazon-corretto-21 github.com/corretto/corretto-docker#main:21/jdk/al2023
After the command completes, you have an image called amazon-corretto-21.
To launch this image locally, run the following command.
Example
docker run -it amazon-corretto-21
You can also push this image to Amazon ECR. See the Pushing an Image topic in the Amazon Elastic Container Registry User Guide for details.
Create an Image
You can create a new Docker image using
Corretto's official Docker Hub image
-
Create a Dockerfile with the following content.
Example
FROM amazoncorretto:21 RUN echo $' \ public class Hello { \ public static void main(String[] args) { \ System.out.println("Welcome to Amazon Corretto!"); \ } \ }' > Hello.java RUN javac Hello.java CMD ["java", "Hello"] -
Build the new image.
Example
docker build -t hello-app . -
Run the new image.
Example
docker run hello-appYou get the following output.
Welcome to Amazon Corretto!