What is the difference between Docker run and Docker compose
· Category: DevOps & Docker
Short answer
docker run launches a single container from the CLI, while Docker Compose orchestrates multiple services, networks, and volumes from a declarative YAML file.
Details
Use docker run for quick tests, one-off scripts, or debugging images. It requires passing every flag manually: ports, volumes, environment variables, and restart policies. Docker Compose simplifies this by codifying the entire stack in docker-compose.yml, making environments reproducible across teams. A typical Compose file references Dockerfile builds for custom services and connects them over a default network. For local development, Docker Compose is the standard because it handles service dependencies, health checks, and log aggregation in one command (docker compose up).
Tips
- Use
docker run --rmfor temporary containers to avoid leaving stopped containers behind. - Pin image tags in Compose files; floating tags cause environment drift.
- Override Compose settings per environment with
docker-compose.override.ymlor env files.