如何将 bash 与基于 Alpine 的 docker 图像一起使用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40944479/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use bash with an Alpine based docker image?
提问by diugalde
I created a docker image from openjdk:8-jdk-alpine but when I try to execute simple commands I get the following errors:
我从 openjdk:8-jdk-alpine 创建了一个 docker 镜像,但是当我尝试执行简单的命令时,我收到以下错误:
RUN bash
/bin/sh: bash: not found
RUN ./gradlew build
env: can't execute 'bash': No such file or directory
回答by anubhava
Alpine docker image doesn't have bash installed by default. You will need to add following commands to get bash
:
默认情况下,Alpine docker 镜像没有安装 bash。您需要添加以下命令来获取bash
:
RUN apk update && apk add bash
If youre using Alpine 3.3+
then you can just do
如果你正在使用,Alpine 3.3+
那么你可以做
RUN apk add --no-cache bash
to keep docker image size small. (Thanks to comment from @sprkysnrky)
保持 docker 图像大小较小。(感谢@sprkysnrky 的评论)
回答by Yuva
Try using RUN /bin/sh
instead of bash.
尝试使用RUN /bin/sh
代替 bash。
回答by user1738546
RUN /bin/sh -c "apk add --no-cache bash"
worked for me.
对我来说有效。
回答by Sahith Vibudhi
To Install bash you can do:
要安装 bash,您可以执行以下操作:
RUN apk add --update bash && rm -rf /var/cache/apk/*
If you do not want to add extra sizeto your image, you can use ash
or sh
that ships with alpine.
如果您不想为图像添加额外的尺寸,您可以使用alpine 附带的ash
或sh
。
Reference: https://github.com/smebberson/docker-alpine/issues/43