Docker compose setup for local development

Back to list2026-05-23
You

I want postgres, redis and my app in compose, but I keep losing the database on every restart.

ChatGPT

The data lives in an anonymous volume unless you name it, and anonymous volumes are discarded by docker compose down -v and often by a plain recreate:

services:
  db:
    image: postgres:17
    environment:
      POSTGRES_PASSWORD: dev
    volumes:
      - pgdata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 5s

volumes:
  pgdata:

The healthcheck matters more than it looks: without it the app starts before postgres accepts connections and you get a flaky first run every morning.

You
pipeline.png
ChatGPT

One more habit worth adopting: keep the compose file for infrastructure only and run the app itself on the host during development. Rebuild times drop to zero and the debugger attaches without any port gymnastics.