-
Notifications
You must be signed in to change notification settings - Fork 18
Closed
Labels
containersPull requests that update containers codePull requests that update containers codeenhancementNew feature or requestNew feature or requestpythonPull requests that update Python codePull requests that update Python code
Description
Description
We need to create a Dockerfile to containerize the FastAPI application for easier deployment and testing. The goal is to create an efficient image that includes all dependencies, prepares the environment, and exposes the necessary ports for FastAPI to run inside a container.
Suggested Approach
- Use an official Python image as the base (
python:3.x-slimor similar). - Install the dependencies from
requirements.txtonly (requirements-lint.txtandrequirements-test.txtare not necessary in production) - Copy the entire application code into the container.
- Expose port
9000(configured FastAPI port). - Copy the SQLite database (
players-sqlite3.db) from thedatafolder into the container. - Use
uvicornto start the FastAPI application on port9000.
Suggested Implementation
# Stage 1: Build
FROM python:3.12-slim-bookworm AS build
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
# Stage 2: Runtime
FROM python:3.12-slim-bookworm AS runtime
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY models ./models
COPY routes ./routes
COPY schemas ./schemas
COPY services ./services
COPY data ./data
COPY main.py .
# Add non-root 'fastapi' user (optional for hardening)
RUN adduser --disabled-password --gecos '' fastapi \
&& chown -R fastapi:fastapi /app
USER fastapi
EXPOSE 9000
ENV PYTHONUNBUFFERED=1
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "9000"]Acceptance Criteria
- Docker image builds without errors.
- The SQLite database file (
players-sqlite3.db) is properly copied into the container and available to the app. - The container runs the FastAPI app on port
9000and is accessible athttp://localhost:9000.
Metadata
Metadata
Assignees
Labels
containersPull requests that update containers codePull requests that update containers codeenhancementNew feature or requestNew feature or requestpythonPull requests that update Python codePull requests that update Python code