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

Viewed 1024

I've been trying to run basic shell commands, ls as an example, but any of them work. So, I've tried to validate if the container has a bash enabled, and answers to similar posts say to run:

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

But any of them work (neither docker exec -it amazing_robinson ls).

This is the error:

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

The container is

 jaegertracing/example-hotrod:latest
2 Answers
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

As I can see hotrod image was built from scratch image. And from the docker hub:

"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

So, I think there is not bash inside this image

If you check the your base image it from scratch.

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

So there is no Bash, ash as the image is from scratch so it will only cotnain hotrod-linux.

To get sh or bash in such cases you need to use multi-stage Dockerfile, you can use the base image in Dockerfile and then copy the binaries from the base image in multi-stage in Dockerfile. Here you go

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"]

so now you can build and test and you will able to run command inside container using docker exec, here is the example

docker build -t myimage .

docker run -dit --name test myimage

#now run
docker exec -it test ash
Related