Hashii1729 commited on
Commit
95c4487
·
1 Parent(s): c86d940

Refactor Dockerfile: improve comments for clarity, streamline installation steps, and enhance user permissions setup

Browse files
Files changed (1) hide show
  1. Dockerfile +20 -25
Dockerfile CHANGED
@@ -1,7 +1,6 @@
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,44 +9,40 @@ RUN apt-get update && apt-get install -y \
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
- # --- Debug: Check Ollama installation ---
39
- RUN echo "=== Ollama Installation Check ===" && \
40
- which ollama || echo "ollama not in PATH" && \
41
- ls -la /usr/local/bin/ollama || echo "ollama not in /usr/local/bin/" && \
42
- ls -la /usr/bin/ollama || echo "ollama not in /usr/bin/" && \
43
- echo "================================="
44
 
45
- # --- Expose ports for FastAPI & Ollama ---
46
  EXPOSE 7860
47
  EXPOSE 11434
48
 
49
- # --- Use non-root user ---
50
  USER appuser
51
 
52
- # --- Start everything ---
53
- CMD ["/app/start.sh"]
 
 
 
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
  && 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"]