Spaces:
Running
Running
Update Dockerfile
Browse files- Dockerfile +12 -32
Dockerfile
CHANGED
@@ -1,61 +1,41 @@
|
|
1 |
# Use a base Ubuntu image
|
2 |
FROM ubuntu:22.04
|
3 |
|
4 |
-
# Set environment variables to prevent interactive prompts
|
5 |
ENV DEBIAN_FRONTEND=noninteractive
|
6 |
|
7 |
-
# Install system dependencies: curl for Ollama,
|
8 |
-
RUN apt update && apt install -y curl
|
9 |
|
10 |
-
#
|
11 |
-
# Create a non-root user named 'user' with user ID 1000.
|
12 |
-
# This matches the user ID that Hugging Face Spaces uses to run the container.
|
13 |
-
# The -m flag creates a home directory at /home/user.
|
14 |
RUN useradd -m -u 1000 user
|
15 |
|
16 |
-
# Install Ollama using its official installation script
|
17 |
-
# This will be run as root, which is correct for system-wide installation.
|
18 |
RUN curl -fsSL https://ollama.com/install.sh | sh
|
19 |
|
20 |
-
# Set the working directory
|
21 |
WORKDIR /app
|
22 |
|
23 |
-
#
|
24 |
-
ENV MODEL_REPO="unsloth/gemma-3-4b-it-GGUF"
|
25 |
-
ENV MODEL_FILENAME="gemma-3-4b-it.Q4_K_M.gguf"
|
26 |
-
ENV MODEL_enableDL="?download=true"
|
27 |
-
|
28 |
-
# This hard code OK.... Download the GGUF model file directly from Hugging Face Hub.
|
29 |
-
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}
|
30 |
-
|
31 |
-
# --- PERMISSIONS FIX 2: COPY FILES WITH OWNERSHIP ---
|
32 |
-
# Copy all application files into the container.
|
33 |
-
# Use the --chown=user flag to set the owner of these files to the 'user' we created.
|
34 |
-
# This is critical for giving the application write permissions.
|
35 |
-
COPY --chown=user Modelfile .
|
36 |
COPY --chown=user app.py .
|
37 |
COPY --chown=user requirements.txt .
|
38 |
COPY --chown=user run.sh .
|
39 |
|
40 |
-
# Install Python dependencies
|
41 |
RUN pip install --no-cache-dir -r requirements.txt
|
42 |
|
43 |
# Make the startup script executable
|
44 |
RUN chmod +x run.sh
|
45 |
|
46 |
-
#
|
47 |
-
# Switch the context of the Dockerfile to our non-root user.
|
48 |
-
# All subsequent commands (including the final CMD) will now be executed as 'user', not 'root'.
|
49 |
USER user
|
50 |
|
51 |
-
# Set environment
|
52 |
-
# tools like pip and transformers cache files in a location writable by the user (/home/user/.cache).
|
53 |
ENV HOME=/home/user \
|
54 |
PATH=/home/user/.local/bin:$PATH
|
55 |
|
56 |
-
# Expose the
|
57 |
EXPOSE 7860
|
58 |
|
59 |
-
# Set the entrypoint
|
60 |
-
# This will now be run as the 'user'.
|
61 |
CMD ["./run.sh"]
|
|
|
1 |
# Use a base Ubuntu image
|
2 |
FROM ubuntu:22.04
|
3 |
|
4 |
+
# Set environment variables to prevent interactive prompts
|
5 |
ENV DEBIAN_FRONTEND=noninteractive
|
6 |
|
7 |
+
# Install system dependencies: curl for Ollama, python3 and pip for the app
|
8 |
+
RUN apt update && apt install -y curl python3 python3-pip
|
9 |
|
10 |
+
# Create a non-root user to solve the Gradio permission error
|
|
|
|
|
|
|
11 |
RUN useradd -m -u 1000 user
|
12 |
|
13 |
+
# Install Ollama using its official installation script (as root)
|
|
|
14 |
RUN curl -fsSL https://ollama.com/install.sh | sh
|
15 |
|
16 |
+
# Set the working directory
|
17 |
WORKDIR /app
|
18 |
|
19 |
+
# Copy only the necessary application files with correct ownership
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
COPY --chown=user app.py .
|
21 |
COPY --chown=user requirements.txt .
|
22 |
COPY --chown=user run.sh .
|
23 |
|
24 |
+
# Install Python dependencies
|
25 |
RUN pip install --no-cache-dir -r requirements.txt
|
26 |
|
27 |
# Make the startup script executable
|
28 |
RUN chmod +x run.sh
|
29 |
|
30 |
+
# Switch to the non-root user
|
|
|
|
|
31 |
USER user
|
32 |
|
33 |
+
# Set home environment for the user
|
|
|
34 |
ENV HOME=/home/user \
|
35 |
PATH=/home/user/.local/bin:$PATH
|
36 |
|
37 |
+
# Expose the Gradio port
|
38 |
EXPOSE 7860
|
39 |
|
40 |
+
# Set the entrypoint to our startup script
|
|
|
41 |
CMD ["./run.sh"]
|