dockerdockerfilecontainersdocker-imagedocker-command

starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory":


I am trying to build an docker image on centos 7 from SCRATCH. I have performed following steps :

FROM scratch
RUN rpm -ivh https://address/app.rpm
RUN YUM install tools 
...
...
CMD ["rpm","start"]

After executing this , I tried to build this dockerfile with command "docker build -t testsid -f ./dockerfile ."

Now I see following error :

Sending build context to Docker daemon  3.072kB
Step 1/16 : FROM scratch
 --->
Step 2/16 : RUN rpm -ivh https://address/app.rpm
 ---> Running in d25a0a879d9e
OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory": unknown

Please let me know whether anyone has suggestion regarding this. ?

Any input will be really helpful.

Thank you.


Solution

  • FROM scratch starts from a totally empty image. The only things that will be in the container filesystem at all are files in /dev, /proc, and /etc that Docker automatically provides. When you say rpm, that command doesn't exist. A string-form RUN command gets wrapped in /bin/sh -c ..., but there is no /bin directory.

    FROM scratch is a somewhat advanced use of Docker. If you're very comfortable with concepts like statically-linked binaries and the differences between bare-string and JSON-array CMD, you can use it to make an extremely small image. For most typical uses you'll want to at least start from something with some sort of distribution and package manager.

    If you need Red Hat's package management tools, the easiest Docker Hub image to start from will be centos:

    FROM centos:8 # includes rpm, yum, /bin directory
    RUN rpm -ivh https://address/app.rpm
    RUN yum install tools
    ...