ming commited on
Commit
7716cd4
·
1 Parent(s): b75970a

Fix Ollama permissions by using /app/.ollama directory instead of /root/.ollama

Browse files
Files changed (1) hide show
  1. Dockerfile +12 -7
Dockerfile CHANGED
@@ -21,8 +21,8 @@ RUN apt-get update \
21
  # Install Ollama
22
  RUN curl -fsSL https://ollama.ai/install.sh | sh
23
 
24
- # Create Ollama directory with proper permissions
25
- RUN mkdir -p /root/.ollama && chmod 755 /root/.ollama
26
 
27
  # Copy requirements first for better caching
28
  COPY requirements.txt .
@@ -40,11 +40,12 @@ RUN echo '#!/bin/bash\n\
40
  # Set Ollama environment variables\n\
41
  export OLLAMA_HOST=0.0.0.0:11434\n\
42
  export OLLAMA_ORIGINS=*\n\
43
- export OLLAMA_MODELS=/root/.ollama/models\n\
 
44
  \n\
45
  # Ensure Ollama directory exists with proper permissions\n\
46
- mkdir -p /root/.ollama\n\
47
- chmod 755 /root/.ollama\n\
48
  \n\
49
  # Start Ollama in background\n\
50
  echo "Starting Ollama server..."\n\
@@ -74,8 +75,12 @@ echo "Starting FastAPI app..."\n\
74
  exec uvicorn app.main:app --host 0.0.0.0 --port 7860' > /app/start.sh \
75
  && chmod +x /app/start.sh
76
 
77
- # Run as root to avoid permission issues with Ollama
78
- # USER appuser
 
 
 
 
79
 
80
  # Expose port (Hugging Face Spaces uses port 7860)
81
  EXPOSE 7860
 
21
  # Install Ollama
22
  RUN curl -fsSL https://ollama.ai/install.sh | sh
23
 
24
+ # Create a writable directory for Ollama in /app
25
+ RUN mkdir -p /app/.ollama && chmod 755 /app/.ollama
26
 
27
  # Copy requirements first for better caching
28
  COPY requirements.txt .
 
40
  # Set Ollama environment variables\n\
41
  export OLLAMA_HOST=0.0.0.0:11434\n\
42
  export OLLAMA_ORIGINS=*\n\
43
+ export OLLAMA_MODELS=/app/.ollama/models\n\
44
+ export HOME=/app\n\
45
  \n\
46
  # Ensure Ollama directory exists with proper permissions\n\
47
+ mkdir -p /app/.ollama\n\
48
+ chmod 755 /app/.ollama\n\
49
  \n\
50
  # Start Ollama in background\n\
51
  echo "Starting Ollama server..."\n\
 
75
  exec uvicorn app.main:app --host 0.0.0.0 --port 7860' > /app/start.sh \
76
  && chmod +x /app/start.sh
77
 
78
+ # Create non-root user and give proper permissions
79
+ RUN groupadd -r appuser && useradd -r -g appuser appuser \
80
+ && chown -R appuser:appuser /app
81
+
82
+ # Switch to non-root user
83
+ USER appuser
84
 
85
  # Expose port (Hugging Face Spaces uses port 7860)
86
  EXPOSE 7860