首页 > 解决方案 > Adding bash binary to a "scratch" docker image

问题描述

I am trying to add bash to a "FROM Scratch" docker image.

I've copied a bash binary from the official bash docker image from docker hub (https://hub.docker.com/_/bash)

docker run -d bash:latest sleep 100
docker cp "$bash_container_id":/usr/local/bin/bash .

My Dockerfile is as follows

FROM jaegertracing/all-in-one:latest
COPY bin/bash /bin
ENV PATH "$PATH:bin/bash"
RUN ["bash"]

Which, when building, results in

Sending build context to Docker daemon  5.213MB
Step 1/4 : FROM jaegertracing/all-in-one:latest
latest: Pulling from jaegertracing/all-in-one
023a144cdcf7: Already exists 
d247ed88ca7d: Already exists 
dc4682d67823: Already exists 
Status: Downloaded newer image for jaegertracing/all-in-one:latest
 ---> b64ba73d1fa4
Step 2/4 : COPY bin/bash /bin
 ---> b6e8ae824d24
Step 3/4 : ENV PATH "$PATH:bin/bash"
 ---> Running in eda2042dff57
Removing intermediate container eda2042dff57
 ---> f1288ded6fcf
Step 4/4 : RUN ["bash"]
 ---> Running in 616c80b0cb8c
OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"bash\": executable file not found in $PATH": unknown

the jaegertracing/all-in-one image is using a "Scratch" base image that contains nothing (no sh, no bash, etc) I am trying to add bash to it for debugging reasons.

Any suggestions? Thanks in advance

标签: bashdockerjaeger

解决方案


你没有$PATH正确配置你的。路径是在其中查找可执行文件的一系列目录,而不是可执行文件本身的路径。此外,由于您要迁移bin/bash/bin/bash,因此您不必担心添加bin/bash到路径中。但无论哪种方式,你想要的是

  1. ENV PATH "$PATH:bin"
  2. ENV PATH "$PATH:/bin"

我相信您想要的是选项#2,因为它是您将 bash 复制到的地方。


推荐阅读