/bin/bash: Command not found in alpine docker

24,852

Solution 1

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

apk update
apk add --no-cache bash

Don't forget set bash as default shell:

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

Solution 2

use the package manager, named apk, this way:

% 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

Solution 3

There is no /bin/bash in alpine:

$ 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.

Share:
24,852
salient
Author by

salient

Updated on January 20, 2020

Comments

  • salient
    salient over 4 years

    I'm trying to run this Makefile in an 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.

    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.

  • salient
    salient over 6 years
    OK, well I had specifically installed it with apk add --no-cache bash
  • Renaud Pacalet
    Renaud Pacalet over 6 years
    Fine. I guess you also installed make and go. It should work, then. As make seems to be there, it is not a matter of using the wrong container. Are you sure you performed all steps in the correct order?
  • Renaud Pacalet
    Renaud Pacalet over 6 years
    By the way, the Makefile you show is it really the one you are using? No comment at the end of the SHELL := /bin/bash line?
  • Bruno Wego
    Bruno Wego over 5 years
    You can change explicit /bin/bash to $(which bash).
  • Bruno Wego
    Bruno Wego over 5 years
    If you wish see the details about it, run getent passwd $USER.
  • Mike Macpherson
    Mike Macpherson over 2 years
    chsh: PAM: Authentication token manipulation error
  • Vignesh S
    Vignesh S about 2 years
    What is shadow?