I tried this Dockerfile
FROM alpine AS build
FROM scratch
COPY --from=build /bin/sleep .
CMD ["sleep", "infinity"]
Build is passing, but after running the image I'm getting this error message:
docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "sleep": executable file not found in $PATH: unknown.
Edit: This question is close related to software development and docker deployment.
Explanation: If application process, which is running into container, isn't designed to run in the foreground, container should be prevented from exiting after startup. That's why sleep
or CMD ["tail", "-f", "/dev/null"]
is used.
As Hans Kilian said, Alpine's sleep
is a link to busybox
, which in turn has dynamic libraries.
This Dockerfile will copy the necessary files and use the correct entrypoint to use sleep:
FROM alpine as build
FROM scratch
COPY --from=build /lib/ld-musl-x86_64.so.1 /lib/ld-musl-x86_64.so.1
COPY --from=build /bin/busybox /bin/busybox
CMD ["/bin/busybox", "sleep", "5"]
Try it with docker build -t sleeper .
and then docker run --rm -it sleeper
.