Docker Compose for Python + Redis

A Python web app (Flask/FastAPI/Django) with Redis for caching or task queues.

python redis api backend cache
compose.yaml
services:
  app:
    build: ./app
    ports:
      - target: 8000
        mode: ingress
    environment:
      - REDIS_URL=redis://cache:6379
    healthcheck:
      test:
        - CMD
        - curl
        - -f
        - http://localhost:8000/
      interval: 30s
      timeout: 5s
      retries: 3
    depends_on:
      - cache
    deploy:
      resources:
        reservations:
          cpus: "0.5"
          memory: 256M
    restart: unless-stopped
  cache:
    image: redis:7-alpine
    ports:
      - target: 6379
        mode: host
    healthcheck:
      test:
        - CMD
        - redis-cli
        - ping
      interval: 10s
      timeout: 5s
      retries: 5
    deploy:
      resources:
        reservations:
          cpus: "0.5"
          memory: 256M
    restart: unless-stopped
    x-defang-redis: true

Services

  • app ./app
  • cache redis:7-alpine

Deploy

$ npx defang@latest compose up

Learn more about Defang