Getting Started with Docker Compose for Development
Docker Compose is an essential tool for modern software development. It allows you to define and run multi-container applications with a simple YAML file.
Why Docker Compose?
Setting up development environments can be painful. Different team members might have different versions of Node.js, Python, or databases installed. Docker Compose solves this by providing:
- Consistent environments across all team members
- Easy onboarding — just run
docker compose up - Isolation from your host system
- Reproducibility of your entire stack
Basic Setup
Here's a minimal docker-compose.yml for a Next.js application:
services:
app:
build:
context: .
target: dev
ports:
- "3000:3000"
volumes:
- ./src:/app/src
- ./content:/app/content
environment:
- NODE_ENV=development
Hot Reloading
The key to a productive Docker development setup is volume mounts. By mounting your source code directory into the container, changes you make on your host machine are immediately reflected inside the container.
volumes:
- ./src:/app/src
This means you can edit files in your favorite editor and see changes instantly in the browser.
Tips
- Use multi-stage builds to keep your images small
- Mount only the directories you need to edit
- Use
WATCHPACK_POLLING=truefor file watching in containers - Keep your
docker-compose.ymlin version control
Conclusion
Docker Compose dramatically simplifies local development. Once set up, your entire team can spin up the full development environment with a single command.