Why does Docker "give executable file `/bin/sh` not found in $PATH"?

Viewed 835

Can some figure out why this Dockerfile

FROM docker.io/fluent/fluent-bit:1.6-debug
RUN ln -sf /usr/share/zoneinfo/Europe/Copenhagen /etc/localtime

gives

STEP 1: FROM docker.io/fluent/fluent-bit:1.6-debug
STEP 2: RUN /usr/local/bin/ln -sf /usr/share/zoneinfo/Europe/Copenhagen /etc/localtime
2021-02-20T19:44:50.000358546Z: executable file `/bin/sh` not found in $PATH: No such file or directory
error running container: error creating container for [/bin/sh -c /usr/local/bin/ln -sf /usr/share/zoneinfo/Europe/Copenhagen /etc/localtime]: : exit status 1
Error: error building at STEP "RUN /usr/local/bin/ln -sf /usr/share/zoneinfo/Europe/Copenhagen /etc/localtime": error while running runtime: exit status 1

If I do

$ docker run -ti fluent-bit:1.6-debug sh
ln -sf /usr/share/zoneinfo/Europe/Copenhagen /etc/localtime

then it works...

2 Answers

Because your docker.io/fluent/fluent-bit:1.6-debug base image is based on a distroless base image: https://docs.fluentbit.io/manual/installation/docker#multi-architecture-images

You can enter the shell and execute command in the container because you are using a debug image version that has busybox in it https://github.com/GoogleContainerTools/distroless#debug-images

More about distroless: https://github.com/GoogleContainerTools/distroless/blob/master/README.md

To achieve what you want do this, specify that the shell is the busybox sh function instead of the default /bin/sh that is nonexistent here.

FROM docker.io/fluent/fluent-bit:1.6-debug
SHELL ["busybox", "sh", "-c"]
RUN ln -sf /usr/share/zoneinfo/Europe/Copenhagen /etc/localtime

Keep in mind that you can do this only with a debug image version. Also keep in mind that distroless images are meant only to run your program and nothing else.

FROM docker.io/fluent/fluent-bit:1.6-debug
RUN ["ln", "-sf",  "/usr/share/zoneinfo/Europe/Copenhagen", "/etc/localtime"]
Related