在临时 Docker 映像上安装 Bash [英] Install Bash on scratch Docker image
问题描述
我目前正在使用第三方 Docker 映像,其 Dockerfile 基于空映像,从 FROM scratch
指令.
I am presently working with a third party Docker image whose Dockerfile is based on the empty image, starting with the FROM scratch
directive.
如何在这样的图像上安装 Bash?我尝试向 Dockerfile 添加一些额外的命令,但显然 RUN
指令本身需要 Bash.
How can Bash be installed on such image? I tried adding some extra commands to the Dockerfile, but apparently the RUN
directive itself requires Bash.
推荐答案
当你从头开始
启动一个 Docker 镜像时,你绝对什么也得不到.通常,您使用其中之一的方式是在您的主机上构建一个静态二进制文件(或者这些天在早期的 Dockerfile 构建阶段),然后将其 COPY
到映像中.
When you start a Docker image FROM scratch
you get absolutely nothing. Usually the way you work with one of these is by building a static binary on your host (or these days in an earlier Dockerfile build stage) and then COPY
it into the image.
FROM scratch
COPY mybinary /
ENTRYPOINT ["/mybinary"]
没有什么能阻止您创建派生图像并将其他二进制文件COPY
放入其中.您要么必须专门构建静态二进制文件,要么安装完整的动态库环境.
Nothing would stop you from creating a derived image and COPY
ing additional binaries into it. Either you'd have to specifically build a static binary or install a full dynamic library environment.
如果您这样做是为了尝试调试容器,则映像中可能没有其他内容.这意味着一件事是你可以用 shell 做的一系列事情非常无聊.另一个是你不会拥有你习惯的标准工具集(没有 ls
或 cp
).如果您可以在没有 bash 的各种扩展的情况下生活,BusyBox 是一个小工具,旨在静态构建和安装在有限的环境中,提供大多数这些标准工具的最小版本.
If you're doing this to try to debug the container, there is probably nothing else in the image. One thing this means is that the set of things you can do with a shell is pretty boring. The other is that you're not going to have the standard tool set you're used to (there is not an ls
or a cp
). If you can live without bash's various extensions, BusyBox is a small tool designed to be statically built and installed in limited environments that provides minimal versions of most of these standard tools.
这篇关于在临时 Docker 映像上安装 Bash的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!