Docker Local Development Guide
Run MySQL, Redis, PostgreSQL, Nginx, and more on localhost using Docker and Docker Compose to unify your local development environment.
Docker is the most commonly used environment solution for modern local development, isolating dependencies through containers. Databases, caches, and reverse proxies can be mapped to localhost ports for integration with Node, PHP, and Python applications on the host machine.
Typical localhost mappings
| Service | Container Port | Host Access |
|---|---|---|
| MySQL | 3306 | localhost:3306 (TCP) |
| PostgreSQL | 5432 | localhost:5432 |
| Redis | 6379 | localhost:6379 |
| Nginx | 80 | http://localhost:8080 |
| Node App | 3000 | http://localhost:3000 |
The mapping format is -p host_port:container_port, for example, -p 8080:80 means that accessing http://localhost:8080 in the browser routes to port 80 of the Nginx container.
Docker Compose Example
docker-compose.yml:
services:
db:
image: mysql:8
ports:
- '3306:3306'
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: app
redis:
image: redis:7
ports:
- '6379:6379'
web:
build: .
ports:
- '3000:3000'
depends_on:
- db
- redisTo start:
docker compose up -dThe application connection string uses the host perspective: set the database host to localhost (or 127.0.0.1) and the port to the mapped port.
Comparison with XAMPP
| Item | Docker | XAMPP |
|---|---|---|
| Isolation | Container level, no interference between projects | Global installation, prone to version conflicts |
| Startup | docker compose up | Control panel Start |
| Use Case | Full stack, microservices, unified team environment | Quick PHP/MySQL setup |
Common Commands
docker ps # Running containers
docker compose logs -f web # View logs
docker compose down # Stop and remove containers
docker exec -it <id> bash # Enter the containerFrequently Asked Questions
Port already in use
Change the host port on the left side of ports, for example, 3307:3306; or stop any existing MySQL/XAMPP services on your machine.
Slow file mounting on Mac/Windows
For projects with many small files, consider placing node_modules in a named volume or using Dev Containers.
Accessing the host from within the container
On Linux, you can use host.docker.internal (also supported by Docker Desktop) to access APIs running on the host machine.
Summary
Docker maps services to various ports on localhost, providing a modern alternative to “installing a bunch of databases on the local machine”; when combined with Compose, it can easily replicate the team’s production environment.