Skip to content

Commit

Permalink
Fix Dockerfile for fastapi
Browse files Browse the repository at this point in the history
  • Loading branch information
GauravWaghmare committed Jul 28, 2024
1 parent 9fba5ce commit e4bfce7
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions Dockerfile
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"]

0 comments on commit e4bfce7

Please sign in to comment.