Files
conference-room-booking-system/backend/Dockerfile

39 lines
1.2 KiB
Docker
Raw Normal View History

# The Python version can be passed as a build argument.
# Default is set to Python 3.13.
ARG PYTHON_VERSION=3.13
# Builder stage
# This stage is used to install dependencies using Poetry and export them to a requirements.txt file.
FROM python:${PYTHON_VERSION}-slim as builder
# Install Poetry in the builder stage
RUN pip install --no-cache-dir poetry
# Set working directory
WORKDIR /app
# Copy the Poetry configuration files
COPY pyproject.toml poetry.lock ./
# Export dependencies to requirements.txt
# This will create a requirements.txt file with the dependencies listed in pyproject.toml
RUN poetry export -f requirements.txt --output requirements.txt --without-hashes --no-dev
# Final stage
# Use a fresh Python image to keep the final image small
FROM python:${PYTHON_VERSION}-slim
# Set working directory
WORKDIR /app
# Copy the requirements.txt generated in the builder stage and install dependencies
COPY --from=builder /app/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy the project source code
COPY src/ src/
# Start fastapi application using uvicorn
EXPOSE 8000
ENV PYTHONPATH=/app/src
CMD ["uvicorn", "backend:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]