-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9fba5ce
commit e4bfce7
Showing
1 changed file
with
13 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,20 @@ | ||
FROM python:3.9-slim as builder | ||
# Use an official Python runtime as the base image | ||
FROM python:3.9-slim | ||
|
||
# Create and change to the app directory. | ||
# Set the working directory in the container | ||
WORKDIR /app | ||
|
||
# Retrieve application dependencies. | ||
# This allows the container build to reuse cached dependencies. | ||
# Expecting to copy go.mod and if present go.sum. | ||
COPY requirements.txt ./ | ||
RUN pip install -r requirements.txt | ||
# Copy the requirements file into the container | ||
COPY requirements.txt . | ||
|
||
# Copy local code to the container image. | ||
COPY . ./ | ||
# Install the required packages | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
# Build the binary. | ||
RUN fastapi run | ||
# Copy the rest of the application code into the container | ||
COPY . . | ||
|
||
# Use the official Debian slim image for a lean production container. | ||
# https://hub.docker.com/_/debian | ||
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds | ||
FROM debian:buster-slim | ||
RUN set -x && apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ | ||
ca-certificates && \ | ||
rm -rf /var/lib/apt/lists/* | ||
# Expose the port that FastAPI will run on | ||
EXPOSE 8000 | ||
|
||
# Copy the binary to the production image from the builder stage. | ||
COPY --from=builder /app/server /app/server | ||
|
||
# Run the web service on container startup. | ||
CMD ["/app/server"] | ||
# Command to run the FastAPI application | ||
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] |