Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +28 -8
Dockerfile
CHANGED
@@ -1,20 +1,40 @@
|
|
1 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
FROM python:3.9-slim
|
3 |
|
4 |
# Set the working directory in the container
|
5 |
WORKDIR /app
|
6 |
|
7 |
-
#
|
8 |
-
|
|
|
9 |
|
10 |
-
# Copy
|
11 |
COPY . /app
|
12 |
|
13 |
-
#
|
14 |
-
RUN
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
#
|
17 |
EXPOSE 7860
|
18 |
|
19 |
-
# Run
|
20 |
CMD ["python", "app.py"]
|
|
|
1 |
+
# Stage 1: Build stage (only used if compiling dependencies)
|
2 |
+
FROM python:3.9-slim as build-stage
|
3 |
+
|
4 |
+
# Set the working directory
|
5 |
+
WORKDIR /app
|
6 |
+
|
7 |
+
# Install build dependencies (only if needed, otherwise skip this stage)
|
8 |
+
# RUN apt-get update && apt-get install -y build-essential gcc
|
9 |
+
|
10 |
+
# Copy requirements file
|
11 |
+
COPY requirements.txt .
|
12 |
+
|
13 |
+
# Install Python dependencies
|
14 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
15 |
+
|
16 |
+
# Stage 2: Final stage
|
17 |
FROM python:3.9-slim
|
18 |
|
19 |
# Set the working directory in the container
|
20 |
WORKDIR /app
|
21 |
|
22 |
+
# Copy the contents from the build stage (dependencies only)
|
23 |
+
COPY --from=build-stage /usr/local/lib/python3.9/site-packages /usr/local/lib/python3.9/site-packages
|
24 |
+
COPY --from=build-stage /usr/local/bin /usr/local/bin
|
25 |
|
26 |
+
# Copy application code
|
27 |
COPY . /app
|
28 |
|
29 |
+
# Remove pip cache and unnecessary files (optional)
|
30 |
+
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
31 |
+
|
32 |
+
# Add non-root user and switch to it for better security
|
33 |
+
RUN useradd -m flaskuser
|
34 |
+
USER flaskuser
|
35 |
|
36 |
+
# Expose the port your Flask app will run on
|
37 |
EXPOSE 7860
|
38 |
|
39 |
+
# Run the Flask app
|
40 |
CMD ["python", "app.py"]
|