SkyNetWalker commited on
Commit
6acaae5
·
verified ·
1 Parent(s): 2038fda

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +43 -29
Dockerfile CHANGED
@@ -1,50 +1,64 @@
1
- # Start with a Python base image, which is convenient for running the Gradio app.
2
- FROM python:3.9
3
 
4
  # Set environment variables to prevent interactive prompts during apt operations
5
  ENV DEBIAN_FRONTEND=noninteractive
6
 
7
- # Install system dependencies: curl for Ollama and wget for model download.
8
- RUN apt-get update && apt-get install -y curl wget
9
 
10
- # Install Ollama using its official installation script.
 
 
 
 
 
 
 
11
  RUN curl -fsSL https://ollama.com/install.sh | sh
12
 
13
- # Set environment variables for the model for easy modification.
14
- ENV MODEL_REPO="unsloth/gemma-3-4b-it-qat-GGUF"
15
- ENV MODEL_FILENAME="gemma-3-4b-it-qat.Q4_K_M.gguf"
16
 
17
- # Create a non-root user and switch to its home directory. This is a best practice for security and avoids permission errors with model caching.
18
- # As seen in the Hugging Face Docker guide. [1]
19
- RUN useradd -m -u 1000 user
20
- WORKDIR /home/user/app
 
 
 
21
 
22
- # Download the GGUF model file directly from Hugging Face Hub.
23
- 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}
24
 
25
- # Copy the application files and set the correct ownership to the new user. [1]
26
- COPY --chown=user:user Modelfile .
27
- COPY --chown=user:user app.py .
28
- COPY --chown=user:user requirements.txt .
29
- COPY --chown=user:user run.sh .
 
 
 
30
 
31
- # Install Python dependencies.
32
  RUN pip install --no-cache-dir -r requirements.txt
33
 
34
- # Make the startup script executable.
35
  RUN chmod +x run.sh
36
 
37
- # Switch to the non-root user. [1]
 
 
38
  USER user
39
 
40
- # Set environment variables for the user and for Ollama.
41
- # This ensures cached models are stored in a writable directory and that Ollama is accessible within the container network. [1]
42
- ENV HOME=/home/user
43
- ENV PATH=/home/user/.local/bin:$PATH
44
- ENV OLLAMA_HOST=127.0.0.1
45
 
46
- # Expose the port for the Gradio application.
47
  EXPOSE 7860
48
 
49
- # Set the command to run our startup script.
 
50
  CMD ["./run.sh"]
 
1
+ # Use a base Ubuntu image
2
+ FROM ubuntu:22.04
3
 
4
  # Set environment variables to prevent interactive prompts during apt operations
5
  ENV DEBIAN_FRONTEND=noninteractive
6
 
7
+ # Install system dependencies: curl for Ollama, wget for model download, git, python3 and pip
8
+ RUN apt update && apt install -y curl wget git python3 python3-pip
9
 
10
+ # --- PERMISSIONS FIX 1: CREATE USER ---
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 inside the container
21
+ WORKDIR /app
 
22
 
23
+ # Define environment variables for the model repository and filename
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
+ # Download the specific GGUF model file directly from Hugging Face Hub.
29
+ RUN wget -O ${MODEL_FILENAME} https://huggingface.co/${MODEL_REPO}/resolve/main/${MODEL_FILENAME}${MODEL_enableDL}
30
 
31
+ # This OK.... Download the GGUF model file directly from Hugging Face Hub.
32
+ #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}
33
 
34
+ # --- PERMISSIONS FIX 2: COPY FILES WITH OWNERSHIP ---
35
+ # Copy all application files into the container.
36
+ # Use the --chown=user flag to set the owner of these files to the 'user' we created.
37
+ # This is critical for giving the application write permissions.
38
+ COPY --chown=user Modelfile .
39
+ COPY --chown=user app.py .
40
+ COPY --chown=user requirements.txt .
41
+ COPY --chown=user run.sh .
42
 
43
+ # Install Python dependencies required by your Gradio application
44
  RUN pip install --no-cache-dir -r requirements.txt
45
 
46
+ # Make the startup script executable
47
  RUN chmod +x run.sh
48
 
49
+ # --- PERMISSIONS FIX 3: SWITCH TO USER ---
50
+ # Switch the context of the Dockerfile to our non-root user.
51
+ # All subsequent commands (including the final CMD) will now be executed as 'user', not 'root'.
52
  USER user
53
 
54
+ # Set environment variables for the user's home directory. This ensures that
55
+ # tools like pip and transformers cache files in a location writable by the user (/home/user/.cache).
56
+ ENV HOME=/home/user \
57
+ PATH=/home/user/.local/bin:$PATH
 
58
 
59
+ # Expose the port that your Gradio application will listen on.
60
  EXPOSE 7860
61
 
62
+ # Set the entrypoint for the container to execute our startup script.
63
+ # This will now be run as the 'user'.
64
  CMD ["./run.sh"]