generated from rafsaf/minimal-fastapi-postgres-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
31 lines (22 loc) · 851 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
# Using Python 3.12 slim image
FROM python:3.12-slim-bullseye AS base
ENV PYTHONUNBUFFERED=1
WORKDIR /app
# Install Poetry
RUN pip install poetry==1.8.2
# Copy only files necessary for dependencies to avoid cache busting
COPY poetry.lock pyproject.toml ./
# Export poetry dependencies to requirements.txt and install them
RUN poetry export -o requirements.txt --without-hashes
RUN pip install --no-cache-dir -r requirements.txt
# Install uvicorn with performance extras
RUN pip install uvicorn[standard]
# Add the rest of the application files
COPY . .
# Optional: Create a non-root user to run the application
RUN addgroup --system app && adduser --system --group app
USER app
# Expose the application on port 8000
EXPOSE 8000
# Run the application
CMD ["sh", "-c", "alembic upgrade head && uvicorn app.main:app --host 0.0.0.0 --port 8000"]