尝试通过 docker exec 获取 bash,但没有任何效果(Jaeger 容器)--> OCI runtime exec 失败

Trying to get bash through docker exec, but nothing works (Jaeger container) --> OCI runtime exec failed

我一直在尝试 运行 基本 shell 命令,例如 ls,但它们中的任何一个都有效。 因此,我尝试验证容器是否启用了 bash,并且对类似帖子的回答是 运行:

docker exec -it amazing_robinson //bin//bash
docker exec -it amazing_robinson /bin/bash
docker exec -it amazing_robinson //bin//sh
docker exec -it amazing_robinson /bin/sh
docker exec -it amazing_robinson sh
docker exec -it amazing_robinson bash

但是它们中的任何一个都有效(docker exec -it amazing_robinson ls)。

这是错误:

OCI runtime exec failed: exec failed: container_linux.go:345: starting container process caused "exec: \"/bin/bash\": stat /bin/bash: no such file or directory": unknown

容器是

 jaegertracing/example-hotrod:latest

如果您从头检查 base image 它。

FROM scratch
EXPOSE 8080 8081 8082 8083
COPY hotrod-linux /go/bin/
ENTRYPOINT ["/go/bin/hotrod-linux"]
CMD ["all"]

所以没有 Bash, ash 因为图像是从头开始的所以它只会包含 hotrod-linux

在这种情况下要获取 sh 或 bash 需要使用多阶段 Dockerfile,您可以在 Dockerfile 中使用基础映像,然后在 Dockerfile 中从多阶段基础映像复制二进制文件。给你

FROM jaegertracing/example-hotrod:latest as base
FROM alpine
COPY --from=base /go/bin/hotrod-linux /go/bin/hotrod-linux
ENTRYPOINT ["/go/bin/hotrod-linux"]
CMD ["all"]

所以现在您可以构建和测试,您将能够使用 docker exec 在容器内 运行 命令,这里是示例

docker build -t myimage .

docker run -dit --name test myimage

#now run
docker exec -it test ash
FROM scratch
EXPOSE 8080 8081 8082 8083
COPY hotrod-linux /go/bin/
ENTRYPOINT ["/go/bin/hotrod-linux"]
CMD ["all"]

https://github.com/jaegertracing/jaeger/blob/master/examples/hotrod/Dockerfile

正如我所见,hotrod 图像是从头图像构建的。来自 docker 中心:

"an explicitly empty image, especially for building images "FROM scratch"...

"This image is most useful in the context of building base images (such as debian and busybox) or super minimal images (that contain only a single binary and whatever it requires, such as hello-world)."

https://hub.docker.com/_/scratch

所以,我认为这张图片里面没有bash