project / Dockerfile
dsid271's picture
build: fix permission error by running uv pip install as root
5f74a52
Raw History Blame Contribute Delete
1 kB
# Use Python 3.12 to perfectly match your local Venv
FROM python:3.12-slim
# Install uv inside the container for ultra-fast, predictable builds
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
# Create the user but STAY as root for the installation steps
RUN useradd -m -u 1000 user
WORKDIR /app
# Copy requirements file (still as root)
COPY ./requirements.txt requirements.txt
# Dynamically strip out the windows environment suffix
RUN sed -i 's/tensorflow-intel/tensorflow/g' requirements.txt
# Run uv installation cleanly into the system environment using root permissions
RUN uv pip install --no-cache-dir --system -r requirements.txt
# Copy the rest of your application code and give ownership to the user
COPY --chown=user:user . /app
# NOW switch to the unprivileged user for security right before launching the app
USER user
ENV PATH="/home/user/.local/bin:$PATH"
# Hugging Face Spaces expects traffic on port 7860
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]