How to build corretto 17 alpine linux image using docker file

6.4k Views Asked by At

I am new to Docker, and I need help to build Corretto 17 Alpine Linux image. I have an existing Dockerfile which build Java 8 Alpine Linux image as below.

FROM alpine:3.17

# install software
RUN apk add --no-cache \
    bash \
    openjdk8-jre

How can I add Corretto 17 command to this Dockerfile to run my application on Corretto 17?

3

There are 3 best solutions below

2
Nidhi257 On BEST ANSWER

I found an aws doc to install Amazon Corretto 17 on Alpine Linux

below is the command that neet to insert in your docker file to install corretto 17.

FROM alpine:3.17
    RUN apk add --no-cache &&\
            wget -O /etc/apk/keys/amazoncorretto.rsa.pub https://apk.corretto.aws/amazoncorretto.rsa.pub && \
            echo "https://apk.corretto.aws" >> /etc/apk/repositories && \
            apk update &&\
            apk add amazon-corretto-17
0
andrewJames On

An approach, based on my comment in this answer:

Use the following to use one of the official Corretto Java images - in this case, using Alpine:

docker pull amazoncorretto:17-alpine-jdk

and then

docker run -it amazoncorretto:17-alpine-jdk /bin/sh

Or, if you want a Dockerfile:

FROM amazoncorretto:17-alpine-jdk
CMD ["/usr/bin/java", "--version"]

If I build the image using this...

docker build -t whateveryouwant .

...then I can run it with:

docker run whateveryouwant 

And the run output is:

openjdk 17.0.6 2023-01-17 LTS
OpenJDK Runtime Environment Corretto-17.0.6.10.1 (build 17.0.6+10-LTS)
OpenJDK 64-Bit Server VM Corretto-17.0.6.10.1 (build 17.0.6+10-LTS, mixed mode, sharing)

This obviously doesn't do anything useful, except to show the Java details.

0
Pino On

You don't need to build those images yourself (and you should not!) because Amazon provides several pre-built images at Docker Hub.

For Java 8 you can choose between JDK (amazoncorretto:8-alpine-jdk) and JRE (amazoncorretto:8-alpine-jre), for Java 17 Amazon provides the JDK only (amazoncorretto:17-alpine-jdk) but you can find a pre-built JRE at https://hub.docker.com/r/pnavato/amazoncorretto-jre. In the same page you can find the Dockerfile you have asked for, if you really want to build the image yourself for any reason.