abanm commited on
Commit
67fb3d1
·
verified ·
1 Parent(s): 479c5fb

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +19 -27
Dockerfile CHANGED
@@ -20,71 +20,63 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
20
  && rm -rf /var/lib/apt/lists/*
21
 
22
  # ----------------------------------------------------------
23
- # 3. Create a Non-Root User
24
  # ----------------------------------------------------------
25
- RUN useradd -m appuser
26
-
27
- # ----------------------------------------------------------
28
- # 4. Set Environment Variables for Ollama
29
- # ----------------------------------------------------------
30
- ENV HOME=/home/appuser
31
- ENV OLLAMA_HOME=/home/appuser/.ollama
32
 
33
- # ----------------------------------------------------------
34
- # 5. Set Permissions for Ollama Directory
35
- # ----------------------------------------------------------
36
- RUN mkdir -p $OLLAMA_HOME && chmod 700 $OLLAMA_HOME
37
 
38
- # ----------------------------------------------------------
39
- # 6. Switch to Non-Root User to Install Ollama
40
- # ----------------------------------------------------------
41
- USER appuser
42
 
43
  # ----------------------------------------------------------
44
- # 7. Install Ollama
45
  # ----------------------------------------------------------
46
- RUN curl -fsSL https://ollama.com/install.sh | bash
47
 
48
  # ----------------------------------------------------------
49
- # 8. Switch Back to Root to Install Python Dependencies
50
  # ----------------------------------------------------------
51
- USER root
 
52
 
53
  # ----------------------------------------------------------
54
- # 9. Set Working Directory for the Application
55
  # ----------------------------------------------------------
56
  WORKDIR /app
57
 
58
  # ----------------------------------------------------------
59
- # 10. Copy and Install Python Requirements
60
  # ----------------------------------------------------------
61
  COPY requirements.txt .
62
  RUN pip3 install --no-cache-dir -r requirements.txt
63
 
64
  # ----------------------------------------------------------
65
- # 11. Copy Application Files
66
  # ----------------------------------------------------------
67
  COPY app.py /app/app.py
68
  COPY entrypoint.sh /entrypoint.sh
69
  RUN chmod +x /entrypoint.sh
70
 
71
  # ----------------------------------------------------------
72
- # 12. Set Environment Variables and Expose Port
73
  # ----------------------------------------------------------
74
  ENV OLLAMA_API_KEY=change_me
75
  EXPOSE 7860
76
 
77
  # ----------------------------------------------------------
78
- # 13. Adjust Ownership of Application Directory
79
  # ----------------------------------------------------------
80
  RUN chown -R appuser:appuser /app
81
 
82
  # ----------------------------------------------------------
83
- # 14. Switch to Non-Root User for Running the Application
84
  # ----------------------------------------------------------
85
  USER appuser
86
 
87
  # ----------------------------------------------------------
88
- # 15. Define Entrypoint
89
  # ----------------------------------------------------------
90
  CMD ["/entrypoint.sh"]
 
20
  && rm -rf /var/lib/apt/lists/*
21
 
22
  # ----------------------------------------------------------
23
+ # 3. Install Ollama as Root
24
  # ----------------------------------------------------------
25
+ # Set OLLAMA_HOME to a writable directory
26
+ ENV OLLAMA_HOME=/ollama-data
 
 
 
 
 
27
 
28
+ # Create the Ollama data directory with appropriate permissions
29
+ RUN mkdir -p $OLLAMA_HOME && chmod 755 $OLLAMA_HOME
 
 
30
 
31
+ # Install Ollama
32
+ RUN curl -fsSL https://ollama.com/install.sh | bash
 
 
33
 
34
  # ----------------------------------------------------------
35
+ # 4. Create a Non-Root User
36
  # ----------------------------------------------------------
37
+ RUN useradd -m appuser
38
 
39
  # ----------------------------------------------------------
40
+ # 5. Set Permissions for Ollama Directory
41
  # ----------------------------------------------------------
42
+ # Ensure appuser has ownership of the Ollama directory
43
+ RUN chown -R appuser:appuser $OLLAMA_HOME
44
 
45
  # ----------------------------------------------------------
46
+ # 6. Set Working Directory for the Application
47
  # ----------------------------------------------------------
48
  WORKDIR /app
49
 
50
  # ----------------------------------------------------------
51
+ # 7. Copy and Install Python Requirements
52
  # ----------------------------------------------------------
53
  COPY requirements.txt .
54
  RUN pip3 install --no-cache-dir -r requirements.txt
55
 
56
  # ----------------------------------------------------------
57
+ # 8. Copy Application Files
58
  # ----------------------------------------------------------
59
  COPY app.py /app/app.py
60
  COPY entrypoint.sh /entrypoint.sh
61
  RUN chmod +x /entrypoint.sh
62
 
63
  # ----------------------------------------------------------
64
+ # 9. Set Environment Variables and Expose Port
65
  # ----------------------------------------------------------
66
  ENV OLLAMA_API_KEY=change_me
67
  EXPOSE 7860
68
 
69
  # ----------------------------------------------------------
70
+ # 10. Adjust Ownership of Application Directory
71
  # ----------------------------------------------------------
72
  RUN chown -R appuser:appuser /app
73
 
74
  # ----------------------------------------------------------
75
+ # 11. Switch to Non-Root User for Running the Application
76
  # ----------------------------------------------------------
77
  USER appuser
78
 
79
  # ----------------------------------------------------------
80
+ # 12. Define Entrypoint
81
  # ----------------------------------------------------------
82
  CMD ["/entrypoint.sh"]