Hashii1729 commited on
Commit
9a2f1ba
·
1 Parent(s): 11e2c0d

Refactor Dockerfile: improve comments for clarity, streamline user creation, and ensure proper permissions for Ollama home directory

Browse files
Files changed (1) hide show
  1. Dockerfile +18 -20
Dockerfile CHANGED
@@ -1,6 +1,7 @@
 
1
  FROM ollama/ollama:0.9.2
2
 
3
- # Install Python and dependencies with security updates
4
  RUN apt-get update && apt-get install -y \
5
  python3 \
6
  python3-pip \
@@ -9,40 +10,37 @@ RUN apt-get update && apt-get install -y \
9
  && apt-get clean \
10
  && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
11
 
12
- # Create non-root user for security
13
  RUN groupadd -r appuser && useradd -r -g appuser -m appuser
14
 
15
- # Set working directory
16
  WORKDIR /app
17
-
18
- # Copy requirements and install Python packages
19
  COPY requirements.txt .
20
- RUN pip3 install --no-cache-dir -r requirements.txt
21
 
22
- # Copy your FastAPI app
 
 
 
23
  COPY fast.py .
24
  COPY app.py .
25
  COPY start.sh .
26
  RUN chmod +x start.sh
27
 
28
- # Create Ollama directory and set permissions
29
- RUN mkdir -p /home/appuser/.ollama && chown -R appuser:appuser /home/appuser/.ollama
30
-
31
- # Change ownership to non-root user
32
- RUN chown -R appuser:appuser /app
33
-
34
- # Set environment variables
35
  ENV OLLAMA_HOST=0.0.0.0:11434
36
  ENV OLLAMA_ORIGINS=*
37
- ENV HOME=/home/appuser
38
 
39
- # Expose ports
 
 
 
40
  EXPOSE 7860
41
  EXPOSE 11434
42
 
43
- # Switch to non-root user
44
  USER appuser
45
 
46
- # Start both Ollama and FastAPI
47
- ENTRYPOINT []
48
- CMD ["bash", "/app/start.sh"]
 
1
+ # Use base Ollama image that has Ollama pre-installed
2
  FROM ollama/ollama:0.9.2
3
 
4
+ # --- System & Python dependencies ---
5
  RUN apt-get update && apt-get install -y \
6
  python3 \
7
  python3-pip \
 
10
  && apt-get clean \
11
  && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
12
 
13
+ # --- Create non-root user ---
14
  RUN groupadd -r appuser && useradd -r -g appuser -m appuser
15
 
16
+ # --- Set up working environment ---
17
  WORKDIR /app
 
 
18
  COPY requirements.txt .
 
19
 
20
+ RUN pip3 install --no-cache-dir --upgrade pip \
21
+ && pip3 install --no-cache-dir -r requirements.txt
22
+
23
+ # --- Copy FastAPI code & start script ---
24
  COPY fast.py .
25
  COPY app.py .
26
  COPY start.sh .
27
  RUN chmod +x start.sh
28
 
29
+ # --- Set environment variables ---
30
+ ENV HOME=/home/appuser
31
+ ENV OLLAMA_HOME=/app/.ollama
 
 
 
 
32
  ENV OLLAMA_HOST=0.0.0.0:11434
33
  ENV OLLAMA_ORIGINS=*
 
34
 
35
+ # --- Create Ollama home with permissions ---
36
+ RUN mkdir -p $OLLAMA_HOME && chown -R appuser:appuser /app
37
+
38
+ # --- Expose ports for FastAPI & Ollama ---
39
  EXPOSE 7860
40
  EXPOSE 11434
41
 
42
+ # --- Use non-root user ---
43
  USER appuser
44
 
45
+ # --- Start everything ---
46
+ CMD ["bash", "/app/start.sh"]