Spaces:
Running
Running
Create Dockerfile
Browse files- Dockerfile +43 -0
Dockerfile
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
# Copy requirements file
|
8 |
+
COPY requirements.txt .
|
9 |
+
|
10 |
+
# Install Python dependencies
|
11 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
12 |
+
|
13 |
+
# Stage 2: Final stage
|
14 |
+
FROM python:3.9-slim
|
15 |
+
|
16 |
+
# Set the working directory in the container
|
17 |
+
WORKDIR /app
|
18 |
+
|
19 |
+
# Copy the contents from the build stage (dependencies only)
|
20 |
+
COPY --from=build-stage /usr/local/lib/python3.9/site-packages /usr/local/lib/python3.9/site-packages
|
21 |
+
COPY --from=build-stage /usr/local/bin /usr/local/bin
|
22 |
+
|
23 |
+
# Add non-root user and switch to it for better security
|
24 |
+
RUN useradd -m flaskuser
|
25 |
+
|
26 |
+
# Copy application code
|
27 |
+
COPY . /app
|
28 |
+
|
29 |
+
# Change ownership of /app to flaskuser after user is created
|
30 |
+
RUN chown -R flaskuser:flaskuser /app
|
31 |
+
|
32 |
+
# Remove pip cache and unnecessary files (optional)
|
33 |
+
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
34 |
+
|
35 |
+
# Switch to the non-root user
|
36 |
+
USER flaskuser
|
37 |
+
|
38 |
+
# Expose the port your Flask app will run on
|
39 |
+
EXPOSE 7860
|
40 |
+
|
41 |
+
# Run the Flask app using gunicorn with an infinite request timeout
|
42 |
+
# CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--timeout", "0", "app:app"]
|
43 |
+
CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--timeout", "0", "--access-logfile", "-", "--error-logfile", "-", "app:app"]
|