问题描述
我目前正在使用第三方Docker映像,其Dockerfile基于空映像,从指令。
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.
推荐答案
这个问题很旧,但我看到了一个类似的问题,来到这里,所以在下面发布以处理这种情况。
The question is old but I see a similar question and came here, SO posting to deal with such case below.
如@David所提到的那样,该图像中没有基于刮擦的图像,如果图像基于刮擦图像,则只需将二进制文件复制到图像即可。
As mentioned by @David there is nothing in such image that is based on scratch, If the image is based on the scratch image they just copy the binaries to image and that's it.
因此,此类映像的破解方法是将二进制文件复制到扩展映像中,并在所需的Docker映像中使用它们。
So the hack around with such image is to copy the binaries into your extend image and use them in your desired docker image.
例如
FROM scratch
ARG binary
COPY $binary /postgres_exporter
EXPOSE 9187
ENTRYPOINT [ "/postgres_exporter" ]
因此,这是从头开始的,我无法安装bash或其他任何东西,我只能将二进制文件复制到
So this is based on scratch and I can not install bash or anything else I can just copy binaries to run.
这是工作,将它们用作多阶段基础映像,将二进制文件和已安装的软件包复制到Docker映像中。
So here is the work, use them as the multi-stage base image, copy the binaries and installed packages in your docker images.
在下面我们需要添加等待
Below we need to add wait-for-it
FROM wrouesnel/postgres_exporter
# use the above base image
FROM debian:7.11-slim
RUN useradd -u 20001 postgres_exporter
USER postgres_exporter
#copy binires
COPY --from=0 /postgres_exporter /postgres_exporter
EXPOSE 9187
COPY wait-for-it.sh wait-for-it.sh
USER root
RUN chmod +x wait-for-it.sh
USER postgres_exporter
RUN pwd
ENTRYPOINT ["./wait-for-it.sh", "db:5432", "--", "./postgres_exporter"]
这篇关于在临时Docker映像上安装Bash的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!