This error
docker: Error response from daemon: OCI runtime create failed:
container_linux.go:348: starting container process caused "exec:
\"/bin/sh\": stat /bin/sh: no such file or directory": unknown.
occurs when creating a docker image from base image eg. scratch
. This is because the resulting image does not have a shell to execute the image. If your use:
ENV EXECUTABLE hello
cmd [$EXECUTABLE]
in your docker file, docker uses /bin/sh to parse the input string. and hence the error. Inspecting on the image, your will find:
$docker inspect
"Entrypoint": [
"/bin/sh",
"-c",
"[$HM_APP]"
]
This means that the ENTRYPOINT or CMD arguments will be parsed using /bin/sh -c. The solution that worked for me is to parse the command as a JSON array of string e.g.
cmd ["hello"]
and inspecting the image again:
"Entrypoint": [
"hello"
]
This removes the dependence on /bin/sh the docker app can now execute the binary file. Example:
FROM scratch
# Environmental variables
# Copy files
ADD . /
# Home dir
WORKDIR /bin
EXPOSE 8083
ENTRYPOINT ["hospitalms"]
Hope this helps someone in future.