chatCPU / Dockerfile
SkyNetWalker's picture
Update Dockerfile
32b998c verified
raw
history blame
2.46 kB
# Use a base Ubuntu image
FROM ubuntu:22.04
# Set environment variables to prevent interactive prompts during apt operations
ENV DEBIAN_FRONTEND=noninteractive
# Install system dependencies: curl for Ollama, wget for model download, git, python3 and pip
RUN apt update && apt install -y curl wget git python3 python3-pip
# --- PERMISSIONS FIX 1: CREATE USER ---
# Create a non-root user named 'user' with user ID 1000.
# This matches the user ID that Hugging Face Spaces uses to run the container.
# The -m flag creates a home directory at /home/user.
RUN useradd -m -u 1000 user
# Install Ollama using its official installation script
# This will be run as root, which is correct for system-wide installation.
RUN curl -fsSL https://ollama.com/install.sh | sh
# Set the working directory inside the container
WORKDIR /app
# Define environment variables for the model repository and filename
ENV MODEL_REPO="unsloth/gemma-3-4b-it-GGUF"
ENV MODEL_FILENAME="gemma-3-4b-it.Q4_K_M.gguf"
ENV MODEL_enableDL="?download=true"
# This hard code OK.... Download the GGUF model file directly from Hugging Face Hub.
RUN wget "https://huggingface.co/unsloth/gemma-3-4b-it-qat-GGUF/resolve/main/gemma-3-4b-it-qat-Q4_K_M.gguf?download=true" -O ${MODEL_FILENAME}
# --- PERMISSIONS FIX 2: COPY FILES WITH OWNERSHIP ---
# Copy all application files into the container.
# Use the --chown=user flag to set the owner of these files to the 'user' we created.
# This is critical for giving the application write permissions.
COPY --chown=user Modelfile .
COPY --chown=user app.py .
COPY --chown=user requirements.txt .
COPY --chown=user run.sh .
# Install Python dependencies required by your Gradio application
RUN pip install --no-cache-dir -r requirements.txt
# Make the startup script executable
RUN chmod +x run.sh
# --- PERMISSIONS FIX 3: SWITCH TO USER ---
# Switch the context of the Dockerfile to our non-root user.
# All subsequent commands (including the final CMD) will now be executed as 'user', not 'root'.
USER user
# Set environment variables for the user's home directory. This ensures that
# tools like pip and transformers cache files in a location writable by the user (/home/user/.cache).
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH
# Expose the port that your Gradio application will listen on.
EXPOSE 7860
# Set the entrypoint for the container to execute our startup script.
# This will now be run as the 'user'.
CMD ["./run.sh"]