Docker Compose for Strapi + PostgreSQL

Strapi headless CMS with PostgreSQL. Build APIs without writing code.

strapi cms postgres headless api
compose.yaml
services:
  strapi:
    build: .
    ports:
      - target: 1337
        mode: ingress
    environment:
      - DATABASE_CLIENT=postgres
      - DATABASE_HOST=db
      - DATABASE_PORT=5432
      - DATABASE_NAME=strapi
      - DATABASE_USERNAME=postgres
      - DATABASE_PASSWORD=${DATABASE_PASSWORD}
      - APP_KEYS=${APP_KEYS}
      - JWT_SECRET=${JWT_SECRET}
    healthcheck:
      test:
        - CMD
        - curl
        - -f
        - http://localhost:1337/_health
      interval: 30s
      timeout: 5s
      retries: 3
    depends_on:
      - db
    deploy:
      resources:
        reservations:
          cpus: "1"
          memory: 1G
    restart: unless-stopped
  db:
    image: postgres:16
    ports:
      - target: 5432
        mode: host
    environment:
      - POSTGRES_DB=strapi
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
    healthcheck:
      test:
        - CMD-SHELL
        - pg_isready -U postgres
      interval: 10s
      timeout: 5s
      retries: 5
    deploy:
      resources:
        reservations:
          cpus: "0.5"
          memory: 256M
    restart: unless-stopped
    x-defang-postgres: true

Services

  • strapi .
  • db postgres:16

Deploy

$ npx defang@latest compose up

Learn more about Defang