I am trying to create a Docker image for my flask application, shown below:
# syntax=docker/dockerfile:1 FROM python:3.9.5-slim-buster as build RUN python3 -m venv /app/venv COPY . /app RUN /app/venv/bin/pip install -r /app/requirements.txt FROM gcr.io/distroless/python3 COPY --from=build /app /app # ENV PATH = "/app/venv/bin:${PATH}" EXPOSE 5000 ENTRYPOINT [ "/app/venv/bin/python3" , "main.py"] Basically, I have two build stages: the first one creates a virtual environment with venv, and the second uses a distroless image and copies the virtual environment (along with the rest of my files) from the previous build stage to the new one.
The Docker images builds without issue, but once I try to run the image with docker run, I get the following error:
docker: Error response from daemon: failed to create shim: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "/app/venv/bin/python3": stat /app/venv/bin/python3: no such file or directory: unknown. This error confuses me, since I know the python executable is located at /app/venv/bin, and I double checked this by exporting the container using docker export <container name> > container.tar and exploring the tar file's contents. From what I can tell, I should not be receiving this error.
What am I doing wrong?
Edit: As requested by @RQDQ, below are bare minimum versions of my requirements.txt and main.py:
requirements.txt:
click==8.1.3 Flask==2.1.2 itsdangerous==2.1.2 Jinja2==3.1.2 MarkupSafe==2.0.1 Werkzeug==2.1.2 main.py:
from flask import Flask app = Flask(__name__, static_folder='build') @app.route("/") def hello_world(): return "<p>Hello, World!</p>" if (__name__ == "__main__"): app.run(use_reloader=False, host='0.0.0.0', port=5000, threaded=True)
main.pyandrequirements.txt?pythonbinary inside your virtual environment is a dynamically linked binary then the "distroless" image might be missing key parts like shared libraries and the dynamic loader.