Spaces:
Sleeping
Sleeping
shrijayan
commited on
Commit
·
86fffcf
1
Parent(s):
1a2035c
Refactor Dockerfile to optimize layer caching and ensure proper user permissions
Browse files- Dockerfile +14 -6
Dockerfile
CHANGED
@@ -1,15 +1,23 @@
|
|
1 |
FROM python:3.9-slim
|
2 |
|
3 |
-
#
|
4 |
-
RUN
|
|
|
|
|
5 |
|
6 |
WORKDIR /app
|
7 |
|
8 |
-
# Copy
|
9 |
-
COPY
|
10 |
-
|
11 |
-
USER appuser
|
12 |
|
|
|
13 |
RUN pip install --no-cache-dir -r requirements.txt
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
1 |
FROM python:3.9-slim
|
2 |
|
3 |
+
# Install system dependencies first as root
|
4 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
5 |
+
gcc python3-dev \
|
6 |
+
&& rm -rf /var/lib/apt/lists/*
|
7 |
|
8 |
WORKDIR /app
|
9 |
|
10 |
+
# Copy requirements first for caching
|
11 |
+
COPY requirements.txt .
|
|
|
|
|
12 |
|
13 |
+
# Install Python dependencies system-wide
|
14 |
RUN pip install --no-cache-dir -r requirements.txt
|
15 |
|
16 |
+
# Copy application files
|
17 |
+
COPY . .
|
18 |
+
|
19 |
+
# Create non-root user and set permissions
|
20 |
+
RUN useradd -m appuser && chown -R appuser:appuser /app
|
21 |
+
USER appuser
|
22 |
+
|
23 |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|