-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
executable file
·39 lines (27 loc) · 973 Bytes
/
Dockerfile
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
# Stage 1: Build the application
FROM python:3.8.10-slim AS builder
WORKDIR /app
# Create and activate a virtual environment
RUN python3.8 -m venv venv
ENV PATH="/app/venv/bin:$PATH"
# Copy and install dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy the application code
COPY . .
# Run the application (if needed during build, e.g., for migrations)
RUN python main.py
# Stage 2: Create a lightweight image for running the application
FROM python:3.8.10-slim
WORKDIR /app
# Copy the virtual environment from the builder stage
COPY --from=builder /app/venv /app/venv
# Set the PATH to include the virtual environment
ENV PATH="/app/venv/bin:$PATH"
# Set up the user (optional but recommended for security)
RUN groupadd -r appuser && useradd -r -g appuser appuser
USER appuser
# Copy your application files (code, configurations, etc.)
COPY . .
# Specify the command to run your application
CMD ["python", "main.py"]