File size: 1,089 Bytes
72b1c3c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1e9882c
 
 
 
 
72b1c3c
 
 
1e9882c
72b1c3c
1e9882c
 
72b1c3c
 
 
 
 
 
1e9882c
72b1c3c
1e9882c
 
72b1c3c
1e9882c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Stage 1: Build stage (only used if compiling dependencies)
FROM python:3.9-slim as build-stage

# Set the working directory
WORKDIR /app

# Install build dependencies (only if needed, otherwise skip this stage)
# RUN apt-get update && apt-get install -y build-essential gcc

# Copy requirements file
COPY requirements.txt .

# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Stage 2: Final stage
FROM python:3.9-slim

# Set the working directory in the container
WORKDIR /app

# Copy the contents from the build stage (dependencies only)
COPY --from=build-stage /usr/local/lib/python3.9/site-packages /usr/local/lib/python3.9/site-packages
COPY --from=build-stage /usr/local/bin /usr/local/bin

# Copy application code
COPY . /app

# Remove pip cache and unnecessary files (optional)
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Add non-root user and switch to it for better security
RUN useradd -m flaskuser
USER flaskuser

# Expose the port your Flask app will run on
EXPOSE 7860

# Run the Flask app
CMD ["python", "app.py"]