OCI runtime exec failed: exec failed: unable to start container process: exec: "bash":
executable file not found in $PATH from docker exec means the running
container has no bash. On an alpine container, ask for
sh instead, or install bash into it first.
The container itself is fine and keeps running; only the extra program you asked
exec to start was not found. Replace bash with sh in
the same command and it runs.
The error
docker run -d --name fix12-dkrun-alp alpine sleep 600
f00c4eeb23ad73457d55483825f08b1f884cbedb500b3352d4842971be734d01
docker exec fix12-dkrun-alp bash -c "echo hi"
OCI runtime exec failed: exec failed: unable to start container process: exec: "bash": executable file not found in $PATH
The exit code was 127. The test ran without -it, and no TTY message appeared;
the program name is the part that failed.
Why it happens
The message names the program docker exec was asked to start,
"bash", and ends with the words "executable file not found in $PATH". The
alpine image lists its shells in /etc/shells, and on this
container that file held /bin/sh and /bin/ash, no
bash:
docker exec fix12-dkrun-alp cat /etc/shells
# valid login shells
/bin/sh
/bin/ash
The same docker exec ... bash -c "echo hi" against a container of
ubuntu:24.04, also started with sleep 600, printed
hi.
The fix
docker exec fix12-dkrun-alp sh -c "echo hi"
hi
When a script really needs bash, install it in the running container with
Alpine's package tool:
docker exec fix12-dkrun-alp apk add --no-cache bash
(1/4) Installing ncurses-terminfo-base (6.6_p20260516-r0)
(2/4) Installing libncursesw (6.6_p20260516-r0)
(3/4) Installing readline (8.3.3-r1)
(4/4) Installing bash (5.3.9-r1)
Executing bash-5.3.9-r1.post-install
Executing busybox-1.37.0-r31.trigger
OK: 10.0 MiB in 20 packages
docker exec fix12-dkrun-alp bash -c "echo hi from $BASH_VERSION"
hi from 5.3.9(1)-release
That install was made in the running container only. To have bash in every container of
the image, put the same line in a Dockerfile; this two-line file was built and run in the
test:
FROM alpine:latest
RUN apk add --no-cache bash
docker build -q -t fix12-dkrun-bash bashimg
sha256:fa7509589bbf6cc40904558233a990ebcc3a73b1df492d608ac4bdcf4a1899e1
docker run --rm fix12-dkrun-bash bash -c "echo hi from $BASH_VERSION"
hi from 5.3.9(1)-release
How it was reproduced
Docker Desktop 4.99.0 on Windows 11 with client and engine 29.9.3, the cached
alpine:latest image (Alpine 3.24.2) and ubuntu:24.04. A PowerShell
script ran each command through cmd /c with stderr merged into stdout, which is
why the commands are shown without a prompt. Both containers were started with
docker run -d ... sleep 600; the apk add steps read the public
Alpine package feed. The failed bash exec ran in two scripts and exited 127
both times. The names fix12-dkrun-alp, fix12-dkrun-ubu,
the image tag fix12-dkrun-bash and the folder bashimg are the
test's own; the containers and the image were removed afterwards.
Frequently asked
- How do I run a shell command in an alpine container?
- Use sh, not bash. In the test docker exec <container> sh -c "echo hi" printed hi where the bash form failed, and /etc/shells listed only /bin/sh and /bin/ash.
- How do I install bash in a running alpine container?
- Run docker exec <container> apk add --no-cache bash. In the test it installed bash 5.3.9 and bash -c worked straight after. A Dockerfile with RUN apk add --no-cache bash built an image where bash worked too.
- Why does docker exec bash work on ubuntu but not on alpine?
- In the test the same docker exec bash -c "echo hi" printed hi in an ubuntu:24.04 container and executable file not found in an alpine one, whose /etc/shells listed no bash.
More decoded errors in the Fixes category. For the same
message from docker run, see
OCI
runtime create failed.