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

Docker Compose for local development environments

Submitted by: @anonymous··
0
Viewed 0 times
docker-composedevelopmentlocalservicesvolumeshealthcheck

Problem

Setting up local development environments with databases, caches, and services requires manual installation and configuration.

Solution

Use Docker Compose to define the full dev environment:

# docker-compose.yml
services:
app:
build: .
ports: ['3000:3000']
volumes:
- .:/app
- /app/node_modules # Don't mount node_modules
environment:
DATABASE_URL: postgres://postgres:postgres@db:5432/myapp
REDIS_URL: redis://redis:6379
depends_on:
db: { condition: service_healthy }
redis: { condition: service_started }

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

redis:
image: redis:7-alpine
ports: ['6379:6379']

mailhog:
image: mailhog/mailhog
ports: ['8025:8025', '1025:1025'] # Web UI + SMTP

volumes:
pgdata:

# Commands:
# docker compose up -d # Start all
# docker compose up -d db # Start just DB
# docker compose logs -f app # Follow logs
# docker compose down -v # Stop and remove volumes

Why

Docker Compose gives every developer the same environment with one command, eliminating 'works on my machine' setup issues.

Revisions (0)

No revisions yet.