Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Docker Image For JRE FROM scratch

I am trying to create a image using JRE without any OS. I tried this Dockerfile which does not work.

    FROM openjdk:11.0.1-jdk-oraclelinux7 as JDK
    RUN jlink --no-header-files --no-man-pages --add-modules java.base,java.desktop,java.logging,java.sql --output /jre

    FROM scratch
    #FROM oraclelinux:7-slim
    COPY --from=JDK /jre /jre
    ARG JAR_FILE
    COPY ${JAR_FILE} /app.jar
    CMD ["/jre/bin/java", "-jar", "/app.jar"]

I am getting following error:

    standard_init_linux.go:190: exec user process caused "no such file or directory"

If I replace scratch with oraclelinux, it works fine. Any clue why I cannot use scratch. The reason to use scratch is to reduce the size of the image.

Any help is appreciated.

like image 661
Jay Rajput Avatar asked Mar 29 '19 11:03

Jay Rajput


People also ask

How do I create a Docker base image from scratch?

Create a simple parent image using scratch Assuming you built the “hello” executable example by using the source code at https://github.com/docker-library/hello-world, and you compiled it with the -static flag, you can build this Docker image using this docker build command: $ docker build --tag hello .


1 Answers

The hotspot sources do not currently support statically linking. See http://mail.openjdk.java.net/pipermail/hotspot-dev/2013-September/010810.html for more info.

like image 191
Virendra Singh Avatar answered Oct 27 '22 15:10

Virendra Singh