corretto / corretto-docker

Dockerfiles for Amazon Corretto Official images.
https://hub.docker.com/_/amazoncorretto
MIT No Attribution
152 stars 63 forks source link

amazoncorretto:17.0.8 on distroless base missing libz.so.1 #171

Closed alex-arana closed 1 year ago

alex-arana commented 1 year ago

Describe the bug

A stripped-down version of amazoncorretto:17 (currently 17.0.8) is being used to package a Java application on top of a distroless image. At runtime, when launching the application, the container returns the following error:

java: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory

To Reproduce

Create a Docker image from the following Dockerfile using docker build -t mycorretto:17 .:

FROM amazoncorretto:17.0.8 AS jdk

RUN jlink \
  --no-header-files \
  --no-man-pages \
  --compress=2 \
  --strip-java-debug-attributes \
  --vm=server \
  --exclude-jmod-section=man \
  --exclude-jmod-section=headers \
  --output /jre \
  --add-modules ALL-MODULE-PATH

RUN cp /usr/lib/jvm/java/bin/jcmd /jre/bin/

FROM gcr.io/distroless/base:nonroot
COPY --from=jdk /jre /usr/lib/jvm

ENTRYPOINT [ "/usr/lib/jvm/bin/java", "-version" ]

Then run the image's default entrypoint using docker run --rm -it mycorretto:17

Expected behavior

Expect to see java version displayed on the console, instead an error is output as per bug description.

Platform information

Repository: dockerhub
Image tag: 17.0.8, 17

Additional context

Modifying the FROM statement on line #1 as follows fixes the problem:

FROM amazoncorretto:17.0.7 AS jdk
lutkerd commented 1 year ago

Thanks for reporting this. A change was made to Corretto on Linux to use the system zlib. You will need to pull that library in to your distroless image.

You can find more information in https://github.com/corretto/corretto-17/issues/118.