Search code examples
bashshelldockerjaeger

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


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

Solution

  • 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