gosign commited on
Commit
b31e68c
·
verified ·
1 Parent(s): 557c02e

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +10 -10
Dockerfile CHANGED
@@ -1,8 +1,8 @@
1
- # Stage 1: Build stage (only used if compiling dependencies)
2
  FROM python:3.9-slim as build-stage
3
 
4
- # Install system dependencies
5
- RUN apt-get update && apt-get install -y libmagic1 file
6
 
7
  # Set the working directory
8
  WORKDIR /app
@@ -13,13 +13,17 @@ COPY requirements.txt .
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
 
@@ -29,12 +33,9 @@ RUN useradd -m flaskuser
29
  # Copy application code
30
  COPY . /app
31
 
32
- # Change ownership of /app to flaskuser after user is created
33
  RUN chown -R flaskuser:flaskuser /app
34
 
35
- # Remove pip cache and unnecessary files (optional)
36
- RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
37
-
38
  # Switch to the non-root user
39
  USER flaskuser
40
 
@@ -42,5 +43,4 @@ USER flaskuser
42
  EXPOSE 7860
43
 
44
  # Run the Flask app using gunicorn with an infinite request timeout
45
- # CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--timeout", "0", "app:app"]
46
- CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--timeout", "0", "--access-logfile", "-", "--error-logfile", "-", "app:app"]
 
1
+ # Stage 1: Build stage (if needed for compiling specific dependencies)
2
  FROM python:3.9-slim as build-stage
3
 
4
+ # Install system dependencies required for Python packages
5
+ RUN apt-get update && apt-get install -y build-essential
6
 
7
  # Set the working directory
8
  WORKDIR /app
 
13
  # Install Python dependencies
14
  RUN pip install --no-cache-dir -r requirements.txt
15
 
16
+
17
  # Stage 2: Final stage
18
  FROM python:3.9-slim
19
 
20
+ # Install system dependencies required at runtime
21
+ RUN apt-get update && apt-get install -y libmagic1 file && apt-get clean
22
+
23
  # Set the working directory in the container
24
  WORKDIR /app
25
 
26
+ # Copy Python dependencies from the build stage
27
  COPY --from=build-stage /usr/local/lib/python3.9/site-packages /usr/local/lib/python3.9/site-packages
28
  COPY --from=build-stage /usr/local/bin /usr/local/bin
29
 
 
33
  # Copy application code
34
  COPY . /app
35
 
36
+ # Change ownership of /app to flaskuser
37
  RUN chown -R flaskuser:flaskuser /app
38
 
 
 
 
39
  # Switch to the non-root user
40
  USER flaskuser
41
 
 
43
  EXPOSE 7860
44
 
45
  # Run the Flask app using gunicorn with an infinite request timeout
46
+ CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--timeout", "0", "--access-logfile", "-", "--error-logfile", "-", "app:app"]