/bin/bash: 在 alpine docker 中找不到命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45860784/
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-18 16:24:48  来源:igfitidea点击:

/bin/bash: Command not found in alpine docker

bashdockerjenkinsmakefilealpine

提问by salient

I'm trying to run this Makefilein an alpinedocker.

我正在尝试Makefilealpinedocker 中运行它。

SHELL := /bin/bash

build:
    GOOS=linux go build -o bin/server main.go

I have ascertained that both bash, make, gois there by interactively going into the container and checking all commands.

我已经确定,这两个bashmakego在那里通过交互进入容器中,并检查所有的命令。

But this command mysteriously fails:

但是这个命令神秘地失败了:

+ make build
make: /bin/bash: Command not found
GOOS=linux go build -o bin/server main.go
make: /bin/bash: Command not found
make: *** [Makefile:17: build] Error 127
script returned exit code 2

I have a real hard time debugging this as it's in a docker and it's jenkinsthat is executing everything.

我真的很难调试它,因为它在 docker 中并且jenkins正在执行所有内容。

回答by Renaud Pacalet

There is no /bin/bashin alpine:

/bin/bash高山没有:

$ docker run -i -t alpine
/ # ls /bin/bash
ls: /bin/bash: No such file or directory

Note that there is no makeor goneither. So, either you checked their existence in your host instead of in alpine, or you are not using vanilla alpine.

请注意,没有makego都没有。因此,要么您检查了它们在您的主机中而不是在 alpine 中的存在,要么您没有使用 vanilla alpine。

回答by Alexandre Fenyo

use the package manager, named apk, this way:

使用名为 apk 的包管理器,如下所示:

% docker run --rm -it alpine /bin/sh
/ #
/ # apk add --no-cache bash
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/community/x86_64/APKINDEX.tar.gz
(1/5) Installing ncurses-terminfo-base (6.0-r8)
(2/5) Installing ncurses-terminfo (6.0-r8)
(3/5) Installing ncurses-libs (6.0-r8)
(4/5) Installing readline (6.3.008-r4)
(5/5) Installing bash (4.3.46-r5)
Executing bash-4.3.46-r5.post-install
Executing busybox-1.25.1-r0.trigger
OK: 12 MiB in 16 packages
/ # which -a bash
/bin/bash

回答by Bruno Wego

To add bashusing Alpine Package Keeper (APK) use the follow command:

bash使用 Alpine Package Keeper (APK)添加,请使用以下命令:

apk update
apk add --no-cache bash

Don't forget set bashas default shell:

不要忘记设置bash为默认shell:

apk add --no-cache shadow
chsh -s /bin/bash
exec /bin/bash