Update Dockerfile
Browse files- Dockerfile +43 -14
Dockerfile
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
# ----------------------------------------------------------
|
2 |
-
# 1. Base
|
3 |
# ----------------------------------------------------------
|
4 |
FROM ubuntu:22.04
|
5 |
|
@@ -7,7 +7,7 @@ FROM ubuntu:22.04
|
|
7 |
ENV DEBIAN_FRONTEND=noninteractive
|
8 |
|
9 |
# ----------------------------------------------------------
|
10 |
-
# 2. Install
|
11 |
# ----------------------------------------------------------
|
12 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
13 |
wget \
|
@@ -20,42 +20,71 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
20 |
&& rm -rf /var/lib/apt/lists/*
|
21 |
|
22 |
# ----------------------------------------------------------
|
23 |
-
# 3.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
# ----------------------------------------------------------
|
25 |
RUN curl -fsSL https://ollama.com/install.sh | bash
|
26 |
|
27 |
# ----------------------------------------------------------
|
28 |
-
#
|
29 |
# ----------------------------------------------------------
|
30 |
-
|
31 |
-
RUN mkdir -p /ollama-data && chmod 777 /ollama-data
|
32 |
|
33 |
# ----------------------------------------------------------
|
34 |
-
#
|
35 |
# ----------------------------------------------------------
|
36 |
WORKDIR /app
|
|
|
|
|
|
|
|
|
37 |
COPY requirements.txt .
|
38 |
RUN pip3 install --no-cache-dir -r requirements.txt
|
39 |
|
40 |
# ----------------------------------------------------------
|
41 |
-
#
|
42 |
# ----------------------------------------------------------
|
43 |
COPY app.py /app/app.py
|
|
|
|
|
44 |
|
45 |
# ----------------------------------------------------------
|
46 |
-
#
|
47 |
# ----------------------------------------------------------
|
48 |
ENV OLLAMA_API_KEY=change_me
|
49 |
EXPOSE 7860
|
50 |
|
51 |
# ----------------------------------------------------------
|
52 |
-
#
|
53 |
# ----------------------------------------------------------
|
54 |
-
|
55 |
-
RUN chmod +x /entrypoint.sh
|
56 |
|
57 |
# ----------------------------------------------------------
|
58 |
-
#
|
59 |
# ----------------------------------------------------------
|
60 |
-
|
61 |
|
|
|
|
|
|
|
|
|
|
1 |
# ----------------------------------------------------------
|
2 |
+
# 1. Base Image
|
3 |
# ----------------------------------------------------------
|
4 |
FROM ubuntu:22.04
|
5 |
|
|
|
7 |
ENV DEBIAN_FRONTEND=noninteractive
|
8 |
|
9 |
# ----------------------------------------------------------
|
10 |
+
# 2. Install System Dependencies
|
11 |
# ----------------------------------------------------------
|
12 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
13 |
wget \
|
|
|
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"]
|