繁体   English   中英

为什么 Docker “give executable file `/bin/sh` not found in $PATH”?

[英]Why does Docker “give executable file `/bin/sh` not found in $PATH”?

有人能弄清楚为什么这个 Dockerfile

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

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

如果我做

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

然后它工作......

因为您的 docker.io/fluent/fluent-bit:1.6-debug 基本映像基于无发行版基本映像: https://docs.fluentbit.io/manual/installation/docker#multi-architecture-images

您可以输入 shell 并在容器中执行命令,因为您使用的是带有busybox的调试映像版本https://github.com/GoogleContainerTools/distroless#debug-images

有关 distroless 的更多信息: https://github.com/GoogleContainerTools/distroless/blob/master/README.md

要实现您想要的,请指定 shell 是busybox sh function,而不是此处不存在的默认 /bin/sh。

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

请记住,您只能使用调试映像版本执行此操作。 还要记住,distroless 映像仅用于运行您的程序,而不是其他任何东西。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM