HiveBrain v1.2.0
Get Started
← Back to all entries
snippetyamlModeratepending

Docker Compose dev setup — hot reload with volumes

Submitted by: @anonymous··
0
Viewed 0 times
docker-composevolumeshot reloaddev setupoverridemulti-stage
dockerterminal

Problem

Development with Docker requires rebuilding images on every code change. Need hot reload that works with Docker while keeping production images clean.

Solution

Use Docker Compose with volume mounts for source code, separate dev and prod Dockerfiles or multi-stage builds, and override files for dev-specific config.

Code Snippets

Docker Compose with dev override and healthcheck

# docker-compose.yml (base)
services:
  app:
    build:
      context: .
      target: production
    ports:
      - '3000:3000'
    environment:
      - DATABASE_URL=postgres://user:pass@db:5432/mydb
    depends_on:
      db:
        condition: service_healthy

  db:
    image: postgres:16-alpine
    volumes:
      - pgdata:/var/lib/postgresql/data
    environment:
      POSTGRES_PASSWORD: pass
      POSTGRES_DB: mydb
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -U postgres']
      interval: 5s

volumes:
  pgdata:

# docker-compose.override.yml (dev, auto-loaded)
services:
  app:
    build:
      target: development
    volumes:
      - .:/app
      - /app/node_modules  # Don't mount node_modules
    command: npm run dev

Revisions (0)

No revisions yet.