How to create an Alpine-based JRE-only Docker image of Amazon Corretto? – Docker

by
Liam Thompson
alpine-linux boot2docker corretto jlink

Quick Fix: Install objcopy tool using apk add --no-cache binutils. Consider using the unofficial amazoncorretto-jre Docker image for a smaller size and production-ready solution.

The Problem:

A software developer is trying to create an Amazon Corretto-based Docker image using jlink to keep the image size small. The developer is facing an error on Alpine while attempting to create the base image. The error suggests that the objcopy program cannot be found. The developer needs to resolve this issue to successfully create the JRE-only Docker image.

The Solutions:

Solution 1: Install `objcopy` and use `–compress=zip-6` or `–compress=zip-9`

To resolve the error “Error: java.io.IOException: Cannot run program "objcopy": error=2, No such file or directory”, you need to install the `objcopy` tool on your Alpine system. This can be done using the following command:

apk add --no-cache binutils

Additionally, it’s important to note that the `–compress=2` option is deprecated in Java 21 and higher. Instead, you should use `–compress=zip-6` or `–compress=zip-9` for compression. Here’s an updated version of the `jlink` command with these changes:

jlink --add-modules ALL-MODULE-PATH --output jre \
      --strip-debug --no-man-pages --no-header-files --compress=zip-6

You can use this command to create the JRE-only image. Alternatively, you can use the unofficial Alpine-based JRE-only image of Amazon Corretto called `amazoncorretto-jre`, which is available on Docker Hub.

Q&A

What is the error about?

Error is about missing objcopy utility in Alpine.

How to fix the error?

Install objcopy utility using apk add –no-cache binutils.

Are there official JRE-only images?

No, but there is an unofficial image called amazoncorretto-jre which can be used.