Spaces:
Sleeping
Sleeping
Commit
·
95c4487
1
Parent(s):
c86d940
Refactor Dockerfile: improve comments for clarity, streamline installation steps, and enhance user permissions setup
Browse files- 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 |
-
#
|
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 |
-
#
|
14 |
RUN groupadd -r appuser && useradd -r -g appuser -m appuser
|
15 |
|
16 |
-
#
|
17 |
WORKDIR /app
|
18 |
-
COPY requirements.txt .
|
19 |
|
20 |
-
|
21 |
-
|
|
|
22 |
|
23 |
-
#
|
24 |
COPY fast.py .
|
25 |
COPY app.py .
|
26 |
COPY start.sh .
|
27 |
RUN chmod +x start.sh
|
28 |
|
29 |
-
#
|
30 |
-
|
31 |
-
ENV OLLAMA_HOME=/app/.ollama
|
32 |
-
ENV OLLAMA_HOST=0.0.0.0:11434
|
33 |
-
ENV OLLAMA_ORIGINS=*
|
34 |
|
35 |
-
#
|
36 |
-
RUN
|
37 |
|
38 |
-
#
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
ls -la /usr/bin/ollama || echo "ollama not in /usr/bin/" && \
|
43 |
-
echo "================================="
|
44 |
|
45 |
-
#
|
46 |
EXPOSE 7860
|
47 |
EXPOSE 11434
|
48 |
|
49 |
-
#
|
50 |
USER appuser
|
51 |
|
52 |
-
#
|
53 |
-
|
|
|
|
|
|
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"]
|