I have the following Dockerfile
FROM golang as builder
ARG CADDY_HASH=4b4e99bdb2e327d553a5f773f827f624181714af
WORKDIR /root/caddy
RUN wget -qO- github.com/caddyserver/caddy/archive/"$CADDY_HASH".tar.gz | tar zx --strip-components=1
RUN set -e; cd cmd/caddy && CGO_ENABLED=0 go build
FROM scratch
COPY --from=builder /root/caddy/cmd/caddy/caddy /
ARG PORT=8000
ENV PORT $PORT
EXPOSE $PORT
CMD /caddy file-server --browse --listen :$PORT
I build and run with this command
DOCKER_BUILDKIT=0 docker build -t caddy-static-docker:latest . && docker run -e PORT=8000 -p 8000:8000 caddy-static-docker:latest
Why this won’t work and I receive this error?
docker: Error response from daemon: failed to create shim: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "/bin/sh": stat /bin/sh: no such file or directory: unknown.
2
Answers
Use a
alpine
image which is a lightweight image to run shell commands and it has/bin/sh
loaded in it.The SCRATCH image is basically empty with nothing inside
/
folder, thus no executables to execute anything that is given as part of CMD.Use an entrypoint instead of CMD
Also note the json syntax (exec form), which leads to the things not run in a subshell.
source: https://docs.docker.com/engine/reference/builder/#cmd
Source: https://docs.docker.com/engine/reference/builder/#entrypoint
Your PORT will still cause issues. Consider hard coding it.