/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
/bin/bash: Command not found in alpine docker
提问by salient
I'm trying to run this Makefile
in an alpine
docker.
我正在尝试Makefile
在alpine
docker 中运行它。
SHELL := /bin/bash
build:
GOOS=linux go build -o bin/server main.go
I have ascertained that both bash
, make
, go
is there by interactively going into the container and checking all commands.
我已经确定,这两个bash
,make
,go
在那里通过交互进入容器中,并检查所有的命令。
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 jenkins
that is executing everything.
我真的很难调试它,因为它在 docker 中并且jenkins
正在执行所有内容。
回答by Renaud Pacalet
There is no /bin/bash
in alpine:
/bin/bash
高山没有:
$ docker run -i -t alpine
/ # ls /bin/bash
ls: /bin/bash: No such file or directory
Note that there is no make
or go
neither. So, either you checked their existence in your host instead of in alpine, or you are not using vanilla alpine.
请注意,没有make
或go
都没有。因此,要么您检查了它们在您的主机中而不是在 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 bash
using Alpine Package Keeper (APK) use the follow command:
要bash
使用 Alpine Package Keeper (APK)添加,请使用以下命令:
apk update
apk add --no-cache bash
Don't forget set bash
as default shell:
不要忘记设置bash
为默认shell:
apk add --no-cache shadow
chsh -s /bin/bash
exec /bin/bash