I created a slim docker file for my app:
FROM python:3.7-slim-stretch AS build RUN python3 -m venv /venv RUN apt-get update && apt-get upgrade -y && apt-get install -y git && apt-get install -y build-essential && rm -rf /var/cache/apt/* /var/lib/apt/lists/* ADD ./requirements.txt /project/ RUN /venv/bin/pip install -r /project/requirements.txt ADD . /project RUN /venv/bin/pip install /project WORKDIR /project FROM python:3.7-slim-stretch AS production COPY --from=build /venv /venv CMD ["/venv/bin/python3","-m", "myapp"]
The docker is building and working. The running python executable is copied from the build image. (Verified, if I remove “/venv/bin” it won’t run).
However, to save some space I want to change my production base docker to:
But then I’m getting an error:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: "/venv/bin/python3": stat /venv/bin/python3: no such file or directory": unknown.
Now, I don’t understand this error. I can see the python executable is there, why he wouldn’t run? Whats in the base python docker image allow it to run?