Bashing Alpine

bradley howington P6rYiIgGT6k unsplash

Photo by Bradley Howington on Unsplash

So this annoying and trivial little problem catches me out every so often. I am always misled by the error message! You’ll see what I mean shortly. For context, it usually happens when I’m working in Docker containers on a build.

Let’s say we have a script like this, saved as


echo "Hello, Bash"

Nice and simple. Let’s build a Docker image with it that runs it. Here’s the Dockerfile.

FROM alpine


RUN ./

Let’s build and see what happens:

$ podman build -f bash.Dockerfile .
STEP 1: FROM alpine
--> 01a74a697df
STEP 3: RUN ./
/bin/sh: ./ not found
Error: error building at STEP "RUN ./": error while running runtime: exit status 127

Aww, snap! The script has to be there, we just copied it into place. So why do we get an error saying that ./ is not found?

The answer is… because we’re trying to run a Bash script on an Alpine image. Alpine doesn’t ship with a Bash shell, so the error is really saying that the interpreter /bin/bash isn’t found, not that the script itself isn’t found. Catches me out every time!

The fix? #!/bin/sh instead. Might need to avoid any Bash-specific syntax. Given this script saved as


echo "Hello, Shell"

Add in an adjusted Dockerfile to pick up the new script instead:

FROM alpine


RUN ./

Building, we get:

$ podman build -f sh.Dockerfile .
STEP 1: FROM alpine
--> d82ae1d0b10
STEP 3: RUN ./
Hello, Shell
--> 8fa27f213ed

We’re all good. The #!/bin/sh directive should attempt to use a compatible shell rather than requiring Bash specifically.

Published 7 Jun 2020

Looking for help? Contact me for consultancy, contract or freelance engagements.