PTPureToolkit
DevOpsLocal-only

FastAPI PostgreSQL Redis Docker Compose

Copy a ready-to-run FastAPI + PostgreSQL + Redis docker-compose.yml for local development. Includes .env.example, commands, and connection strings — no signup.

This tool runs locally in your browser. Your input is not uploaded.

No uploadsNo server logsNo runtime APIsBrowser-only transforms

Prefilled local output

Copy the generated result or open the full tool to adjust inputs locally.

Stack preset

FastAPI + PostgreSQL + Redis

docker-compose.yml

services:
  api:
    image: "python:3.12-slim"
    command: "uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload"
    env_file:
      - .env
    ports:
      - "8000:8000"
    depends_on:
      - db
    volumes:
      - ".:/app"
    working_dir: /app
    networks:
      - app_network
  db:
    image: "postgres:16-alpine"
    environment:
      POSTGRES_DB: "${POSTGRES_DB}"
      POSTGRES_USER: "${POSTGRES_USER}"
      POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}"
    ports:
      - "5432:5432"
    volumes:
      - "postgres_data:/var/lib/postgresql/data"
    healthcheck:
      test:
        - CMD-SHELL
        - "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"
      interval: "10s"
      timeout: "5s"
      retries: 5
    networks:
      - app_network
  redis:
    image: "redis:7-alpine"
    ports:
      - "6379:6379"
    volumes:
      - "redis_data:/data"
    healthcheck:
      test:
        - CMD-SHELL
        - redis-cli ping
      interval: "10s"
      timeout: "5s"
      retries: 5
    networks:
      - app_network
volumes:
  postgres_data: {}
  redis_data: {}
networks:
  app_network:
    driver: bridge


# .env.example
COMPOSE_PROJECT_NAME=fastapi_app
APP_PORT=8000
APP_ENV=development
APP_SECRET=change-me
POSTGRES_DB=app
POSTGRES_USER=app
POSTGRES_PASSWORD=change-me
DATABASE_URL=postgresql://app:change-me@db:5432/app
DATABASE_PORT=5432
REDIS_URL=redis://redis:6379/0
REDIS_PORT=6379


# Commands
cp .env.example .env
docker compose up -d --build
docker compose ps
docker compose logs -f api
docker compose exec api sh
docker compose down
docker compose down -v  # remove named volumes and local data

# Notes
PostgreSQL internal: postgresql://app:${POSTGRES_PASSWORD}@db:5432/app
PostgreSQL local: postgresql://app:${POSTGRES_PASSWORD}@localhost:${DATABASE_PORT}/app
Redis internal: redis://redis:6379/0
Redis local: redis://localhost:${REDIS_PORT}/0
Preset: FastAPI + PostgreSQL + Redis
Mode: development

Notes:
- Review image tags, commands, and mounted paths for your actual application layout.
- Secrets are represented as environment variables in .env.example; replace placeholder values before use.
- Healthchecks are included for supported infrastructure services.
- Named Docker volumes are enabled for local persistence.

Examples

FastAPI PostgreSQL Redis Docker Compose

Copy a ready-to-run FastAPI + PostgreSQL + Redis docker-compose.yml for local development. Includes .env.example, commands, and connection strings — no signup.

FastAPI + PostgreSQL + Redis

How it works

  1. FastAPI PostgreSQL Redis Docker Compose gives you a practical Compose baseline for Python APIs with Postgres persistence and Redis cache or queue support. It uses environment variables for secrets, named services for local networking, and readable service names so the generated file is easy to adapt.
  2. This preset is meant for developers who want to start from a working multi-service skeleton instead of writing YAML from scratch. The generated output includes docker-compose.yml, .env.example, common commands, and connection notes.
  3. Treat the result as infrastructure scaffolding. Before production, review image pinning, TLS termination, backup policy, resource limits, secret management, and whether database ports should be exposed outside the Compose network.

Limitations

  • This preset targets a common workflow and should be reviewed against your production environment.
  • Generated output is deterministic and local-first, but scheduler, log, or infrastructure dialects can vary.
  • Use the full parent tool when you need to adjust fields, ports, options, or sample inputs.

FAQ

Is this FastAPI + PostgreSQL + Redis Docker Compose file production-ready?

It is a strong starter, not a hardened production deployment. Review secrets, TLS, backups, resource limits, and network exposure before production use.

Does the builder store my stack configuration?

No. Preset generation is static and the interactive builder runs locally in the browser.

Can I download the generated Compose files?

Yes. The page exposes copyable and downloadable output for docker-compose.yml and related notes.

Related tools