-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDockerfile
More file actions
43 lines (31 loc) · 1.04 KB
/
Dockerfile
File metadata and controls
43 lines (31 loc) · 1.04 KB
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
42
43
# Stage 1: Build stage
FROM python:3.9.16-slim AS builder
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# Create and set the working directory
WORKDIR /app
# Copy the requirements file to the container
COPY requirements.txt /app/
# Install dependencies
RUN pip install --upgrade pip && \
pip install --no-cache-dir -r requirements.txt
# Stage 2: Final stage
FROM python:3.9.16-slim
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# Create and set the working directory
WORKDIR /app
# Copy installed packages from the builder stage
COPY --from=builder /usr/local/lib/python3.9/site-packages /usr/local/lib/python3.9/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
# Copy the application files
COPY . /app/
# Expose the port the app will run on
EXPOSE 3301
# Use a non-root user for better security
RUN adduser --disabled-password --gecos '' appuser && chown -R appuser /app
USER appuser
# Command to run the FastAPI app using Uvicorn
CMD ["python3", "main.py"]