Docker Compose for Phoenix + PostgreSQL

An Elixir Phoenix application with PostgreSQL. Highly concurrent and fault-tolerant.

elixir phoenix postgres fullstack
compose.yaml
services:
  web:
    build: .
    ports:
      - target: 4000
        mode: ingress
    environment:
      - DATABASE_URL=postgresql://postgres:${POSTGRES_PASSWORD}@db:5432/phoenix
      - SECRET_KEY_BASE=${SECRET_KEY_BASE}
      - PHX_HOST=example.com
      - PORT=4000
    healthcheck:
      test:
        - CMD
        - curl
        - -f
        - http://localhost:4000/
      interval: 30s
      timeout: 5s
      retries: 3
    depends_on:
      - db
    deploy:
      resources:
        reservations:
          cpus: "0.5"
          memory: 256M
    restart: unless-stopped
  db:
    image: postgres:16
    ports:
      - target: 5432
        mode: host
    environment:
      - POSTGRES_DB=phoenix
      - 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

  • web .
  • db postgres:16

Deploy

$ npx defang@latest compose up

Learn more about Defang