Image Overview: jdk

Overview: jdk Chainguard Image

Minimalist Wolfi-based Java JDK image using using OpenJDK. Used for compiling Java applications.

Download this Image

The image is available on cgr.dev:

docker pull cgr.dev/chainguard/jdk:latest

Java Application Example

This section outlines how you can build a Java application with the Chainguard JDK Image.

Start by creating a sample Java class named HelloWolfi.java:

cat >HelloWolfi.java <<EOL
class HelloWolfi
{
    public static void main(String args[])
    {
        System.out.println("Hello Wolfi users!");
    }
}
EOL

Then create a multistage Dockerfile, adding the Java class you just created:

cat >Dockerfile <<EOL
FROM cgr.dev/chainguard/jdk

COPY HelloWolfi.java /home/build/
RUN javac HelloWolfi.java

FROM cgr.dev/chainguard/jre

COPY --from=0 /home/build/HelloWolfi.class /app/
CMD ["HelloWolfi"]
EOL

Following that, you can build the image:

docker build -t my-java-app .

Note that this example tags the image with my-java-app. You can now run the image by referencing this tag, as in the following command:

docker run my-java-app
Hello Wolfi users!

Last updated: 2024-03-01 12:14