如何将 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 22:28:23  来源:igfitidea点击:

How to use bash with an Alpine based docker image?

bashdockerdockerfilealpine

提问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/shinstead 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 ashor shthat ships with alpine.

如果您不想为图像添加额外的尺寸,您可以使用alpine 附带的ashsh

Reference: https://github.com/smebberson/docker-alpine/issues/43

参考:https: //github.com/smebberson/docker-alpine/issues/43