Skip to content

[5.1 Docker] Set up Docker Compose for Backend and Database #38

@fIyingPhoenix

Description

@fIyingPhoenix

Milestone: Milestone 5: Infrastructure & Tools
Category: 5.1 Docker
Task: Set up Docker Compose to orchestrate the backend API and database services.


Description

This task involves creating a docker-compose.yml file to easily manage the orchestration of the backend API and the database container(s). Docker Compose will define and run multi-container Docker applications, simplifying the management and deployment of the backend API and its dependencies (MySQL).


Subtasks:

  • Create a docker-compose.yml file at the root of the project
  • Define services for:
    • Backend API (Python container using the Dockerfile created in Dockerfile for backend API)
    • Database (PostgreSQL/MySQL or any other used database for the backend)
  • Set up environment variables for both services (e.g., database credentials, API keys)
  • Configure a network for communication between containers (e.g., a custom network like app-network)
  • Define ports to expose for the backend API and database (e.g., backend on port 5000, database on default ports)
  • Add volume mounts for persistent data storage (e.g., for database data)
  • Ensure the backend waits for the database service to be ready before starting (using depends_on in Docker Compose)
  • Create a .env file for environment variables (e.g., database username/password, API keys) and use it with Docker Compose
  • Verify that both services can be brought up and down using Docker Compose commands (docker-compose up, docker-compose down)
  • Test that the backend API correctly connects to the database in the Docker Compose environment
  • Document how to use Docker Compose for local development and production in the README

Technical Considerations:

  • Make sure to include the necessary database container (e.g., postgres:latest, mysql:latest)
  • Configure Docker Compose for multi-stage builds if required, ensuring production readiness
  • Ensure proper volume setup for persistent data (database, application state)
  • Verify network settings to ensure proper communication between containers
  • Handle secrets like database passwords via .env or Docker Secrets for production use

Acceptance Criteria:

  • The docker-compose.yml file is set up to run the backend API and database containers
  • The backend and database communicate correctly within the Docker Compose setup
  • The docker-compose up command successfully spins up the services
  • Documentation on how to use Docker Compose is added to the README file

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions