Getting Started with Amazon Corretto 8 on Docker Images - Amazon Corretto

Getting Started with Amazon Corretto 8 on Docker Images

This topic describes how to build and launch a Docker image that uses Amazon Corretto 8. You must have the latest version of Docker installed.

Using the official image for Amazon Corretto 8.

Amazon Corretto 8 is available as an official image on Docker Hub. The following example runs a container and displays Corretto's version.

docker run amazoncorretto:8 java -version

Output:

openjdk version "1.8.0_252" OpenJDK Runtime Environment Corretto-8.252.09.1 (build 1.8.0_252-b09) OpenJDK 64-Bit Server VM Corretto-8.252.09.1 (build 25.252-b09, mixed mode)

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. Once you have logged in, Corretto 8 images can be pulled or run using one of the following commannds:

docker pull 489478819445.dkr.ecr.us-west-2.amazonaws.com/amazoncorretto:8 docker run -it 489478819445.dkr.ecr.us-west-2.amazonaws.com/amazoncorretto:8 /bin/bash

You can see the list of available images using:

aws ecr list-images --region us-west-2 --registry-id 489478819445 --repository-name amazoncorretto

Amazon Corretto on Alpine

Amazon Corretto on Alpine Linux images are available in ECR and Dockerhub

Using ECR

docker pull 489478819445.dkr.ecr.us-west-2.amazonaws.com/amazoncorretto:11-alpine-jdk docker run -it 489478819445.dkr.ecr.us-west-2.amazonaws.com/amazoncorretto:11-alpine-jdk /bin/sh

Using dockerhub

docker pull amazoncorretto/amazoncorretto:11-alpine-jdk docker run -it amazoncorretto/amazoncorretto:11-alpine-jdk /bin/sh

Build a Docker Image with Amazon Corretto 8

Run the following command to build an image that uses Amazon Corretto 8.

docker build -t amazon-corretto-8 github.com/corretto/corretto-docker#master:8/jdk/al2

After the command completes, you have an image called amazon-corretto-8.

To launch this image locally, run the following command.

docker run -it amazon-corretto-8

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.

  1. Create a Docker file with this content.

    FROM amazoncorretto:8 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"]
  2. Build the new image.

    docker build -t hello-app .
  3. Run the new image.

    docker run hello-app

    You get the following output.

    Welcome to Amazon Corretto!