I am learning docker, and referred to online course. After some comfort level, I am now trying to make a dockerized java image, a simple Java app.
I am trying to make the dockerized Java app without having any minimal OS, and hence using FROM scratch in the Dockerfile. The below are the contents:
FROM scratch
ADD FirstJavaApp.class .
RUN yum -y install java
CMD java FirstJavaApp
As I understand dockerized image of any App should have all the dependencies met (and toward this aim, I have added the yum -y install java in the Dockerfile).
Now when I am building the image using this Dockerfile, it is giving me the following error:
sudo docker build -t javaappusingscratch .
Sending build context to Docker daemon 377.8MB
Step 1/4 : FROM scratch
--->
Step 2/4 : ADD FirstJavaApp.class .
---> Using cache
---> c624d7dc7c21
Step 3/4 : RUN yum -y install java
---> Running in 702829f38ad8
container_linux.go:265: starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory"
oci runtime error: container_linux.go:265: starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory"
However, if I replace FROM scratch with FROM centos it is working fine. As I understand that scratch don't have any minimal OS and my aim is to build the image which have just the application and its dependencies, and this is what the aim of docker images is.
So is there something which I am missing or not understood well? Can anyone help me understand this?