Getting Started with Amazon Corretto 17 on Docker Images
This topic describes how to build and launch a Docker image that uses Amazon Corretto 17. You must have the latest version of Docker installed.
Using the official image for Amazon Corretto 17.
Amazon Corretto 17 is available as an official image on Docker Hub
docker run amazoncorretto:17 java -version
Output:
openjdk version "17.0.0" 2021-09-14 LTS OpenJDK Runtime Environment Corretto-17;.0.0.35.1 (build 17;+35-LTS) OpenJDK 64-Bit Server VM Corretto-17;.0.0.35.1 (build 17;+35-LTS, mixed mode, sharing)
Using the Corretto ECR Instance
To use the Corretto ECR instance, first authenticate the docker client to the Corretto
registry ( registry id : 489478819445) with the help of the instructions in this page
docker pull public.ecr.aws/amazoncorretto/amazoncorretto:17 docker run -it public.ecr.aws/amazoncorretto/amazoncorretto:17 /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
Dockerhub
Using dockerhub
docker pull amazoncorretto:17-alpine-jdk docker run -it amazoncorretto:17-alpine-jdk /bin/sh
Build a Docker Image with Amazon Corretto 17
Run the following command to build an image that uses Amazon Corretto 17.
docker build -t amazon-corretto-17 github.com/corretto/corretto-docker#main:17/jdk/al2
After the command completes, you have an image called amazon-corretto-17.
To launch this image locally, run the following command.
docker run -it amazon-corretto-17
You can also push this image to . See the Pushing an Image topic in the 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.
FROM amazoncorretto:17 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.
docker build -t hello-app .
-
Run the new image.
docker run hello-app
You get the following output.
Welcome to Amazon Corretto 17!