-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
46 lines (31 loc) · 974 Bytes
/
Copy pathDockerfile
File metadata and controls
46 lines (31 loc) · 974 Bytes
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
44
45
46
# Builder Stage ---
FROM python:3.12-slim AS builder
# Set the working directory in the container.
WORKDIR /app
# Create a non-root user
RUN useradd --create-home appuser
# Create a venv
ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
# Copy and install requirements
COPY backend/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Final Stage --
FROM python:3.12-slim AS final
# Set working directory
WORKDIR /app
# Create the same user
RUN useradd --create-home appuser
# Copy over the venv
COPY --from=builder /opt/venv /opt/venv
# Copy over application code
COPY --chown=appuser:appuser backend/app ./app
# Switch to the new user
USER appuser
# Activate the venv
ENV PATH="/opt/venv/bin:$PATH"
# Expose the port the app will run on
EXPOSE 8000
# Run the app using Uvicorn
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--proxy-headers", "--ws-ping-interval", "20"]