A Bash script copied into an `alpine` image fails with `env: can't execute 'bash': No such file or directory`.
BeginnerTroubleshootingTroubleshooting: tools, portability, permissions and environment
Answer
Likely causes → Alpine ships BusyBox ash as /bin/sh and does not include Bash. The shebang #!/usr/bin/env bash finds nothing.
Diagnose →
docker run --rm alpine:3.20 sh -c 'command -v bash || echo "no bash"'
head -1 entrypoint.sh
Fix → Install Bash in the image, or make the script POSIX sh and change the shebang:
FROM alpine:3.20
RUN apk add --no-cache bash
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
If you convert to #!/bin/sh, check it with shellcheck -s sh entrypoint.sh to catch Bashisms.
Prevent → Decide per image which shell you target, and lint with the matching ShellCheck dialect in CI.
More on Troubleshooting: tools, portability, permissions and environment
On a Mac, `sed -i 's/replicas: 2/replicas: 3/' deploy.yaml` fails with `sed: 1: "deploy.yaml": extra characters at the end of d command`.BeginnerA cleanup script fails on a developer's Mac with `date: illegal option -- d`.BeginnerA script that works on Ubuntu fails in an Alpine-based CI image with `grep: unrecognized option: P`.IntermediateAn `awk` one-liner works on your RHEL box but fails on Ubuntu with `awk: line 1: function gensub never defined`.Intermediate`comm -23 expected.txt installed.txt` prints `comm: file 1 is not in sorted order`, even though both files were produced with `sort`.Intermediate`grep ERROR /var/log/app/app.log` prints only `grep: /var/log/app/app.log: binary file matches`.Beginner