-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile.prod
49 lines (34 loc) · 1.64 KB
/
Dockerfile.prod
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
47
48
49
# https://fastapi.tiangolo.com/deployment/docker/#docker-image-with-poetry
# First stage
FROM python:3.12.4-slim as requirements-stage
# Set /tmp as the current working directory.
WORKDIR /tmp
# Install Poetry
RUN pip install poetry
# Copy the pyproject.toml and poetry.lock files to the /tmp directory.
COPY ./pyproject.toml ./poetry.lock* /tmp/
# Generate the requirements.txt file.
RUN poetry export -f requirements.txt --output requirements.txt --without-hashes
# This is the final stage, anything here will be preserved in the final container image.
FROM python:3.12.4-slim
# Install gcc and other dependencies
RUN apt-get update && apt-get install -y \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# Set the current working directory to /code.
WORKDIR /code
# Copy the requirements.txt file to the /code directory.
# This file only lives in the previous Docker stage, that's why we use --from-requirements-stage to copy it.
COPY --from=requirements-stage /tmp/requirements.txt /code/requirements.txt
# Install the package dependencies in the generated requirements.txt file.
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
# Copy the app directory to the /code directory.
COPY ./app /code/app
# Make port 80 available to the world outside this container
EXPOSE 80
# Healthcheck
HEALTHCHECK --interval=5s --timeout=5s --retries=3 \
CMD curl -f http://localhost:8081/health || exit 1
# Run the uvicorn command, telling it to use the app object imported from app.main.
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]
# CMD ["uvicorn", "app.main:app", "--proxy-headers", "--host", "0.0.0.0", "--port", "80"]