Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python docker image fails because of missing shell / bash in the image

I have the following Dockerfile:

FROM python:3-alpine
WORKDIR /usr/src/app
COPY requirements.txt .
RUN pip install -qr requirements.txt
COPY target-watch.py .
CMD ["python3", "./target-watch.py"]

If I deploy this to a Kubernetes cluster the build went fine, but I got an error from the Kubernetes logs. To verfiy my image I run the following command:

docker run --rm -it --entrypoint /bin/bash  docker-conveyor.xxx.com/myorg/my_cron_jobs:2021.12.08_03.51_abcdef

Which gives me this response:

docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "/bin/bash": stat /bin/bash: no such file or directory: unknown.

How can this be fixed? I assume a shell is missing in my image. How do i have to change my Dockerfile to make it work without any errors?

like image 993
Test Me Avatar asked Dec 04 '25 09:12

Test Me


1 Answers

Your container image doesn't have bash so you should use /bin/sh instead of /bin/bash.

docker run --rm -it --entrypoint /bin/sh  docker-conveyor.xxx.com/myorg/my_cron_jobs:2021.12.08_03.51_abcdef

Alpine docker image doesn't have bash installed by default. You will need to add the following commands to get bash:

RUN apk update && apk add bash

If you're using Alpine 3.3+ then you can just do

RUN apk add --no-cache bash
like image 124
Hamid Ostadvali Avatar answered Dec 06 '25 23:12

Hamid Ostadvali



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!