FROM python:3.10 # 1. System dependencies RUN apt-get update && apt-get install -y libgl1-mesa-glx libglib2.0-0 # 2. Install Poetry into /usr/local/poetry ENV POETRY_HOME="/usr/local/poetry" RUN curl -sSL https://install.python-poetry.org | python3 - --yes # Put Poetry on PATH ENV PATH="$POETRY_HOME/bin:$PATH" # 3. Create a non-root user RUN useradd -m -u 1000 user # 4. Create /code folder and set ownership RUN mkdir /code && chown user:user /code # 5. Switch to that user BEFORE installing dependencies WORKDIR /code USER user # 6. Copy only the dependency files first COPY --chown=user:user pyproject.toml poetry.lock /code/ # 7. Install dependencies as the non-root user RUN poetry install --no-root --no-interaction --no-ansi # 8. Copy the rest of your source code COPY --chown=user:user . /code # 9. Expose your port EXPOSE 7860 # 10. Launch your app with Poetry CMD ["poetry", "run", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]