The issue is with how CMD and ENTRYPOINT work together. Your CMD isn't working because it is trying to run bash with no arguments, rather than setting up python as the base command. Here's how I’ll fix this:
FROM python:3.11-slim
ENTRYPOINT ["python"]
The difference is:
So with ENTRYPOINT ["python"]
:
docker run image --version
becomes python --version
docker run image script.py
becomes python script.py
Also, this blogpost breaks these concepts down pretty well. https://www.docker.com/blog/docker-best-practices-choosing-between-run-cmd-and-entrypoint/