gosign commited on
Commit
72b1c3c
·
verified ·
1 Parent(s): 13fad22

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +28 -8
Dockerfile CHANGED
@@ -1,20 +1,40 @@
1
- # Use an official Python runtime as a parent image
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  FROM python:3.9-slim
3
 
4
  # Set the working directory in the container
5
  WORKDIR /app
6
 
7
- # Switch to root user to ensure installation permissions
8
- USER root
 
9
 
10
- # Copy the current directory contents into the container at /app
11
  COPY . /app
12
 
13
- # Install any needed packages specified in requirements.txt
14
- RUN pip install --no-cache-dir -r requirements.txt
 
 
 
 
15
 
16
- # Make port 7860 available to the world outside this container
17
  EXPOSE 7860
18
 
19
- # Run app.py when the container launches
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"]