Imagine you're shipping an app to production. Your code runs perfectly on your laptop, but it crashes on the server. Sound familiar?
Click each container below to see what happens when dependencies aren't isolated:
Docker is a platform that packages your application and all its dependencies into standardized, isolated units called containers.
Key Concept: Containers are lightweight, portable, and consistent across any environmentβlaptop, test server, or production cloud.
# Pull an image from Docker Hub
docker pull nginx:latest
# Run a container from an image
docker run -d -p 8080:80 --name my-nginx nginx:latest
# List running containers
docker ps
# Stop and remove a container
docker stop my-nginx && docker rm my-nginx
Docker Compose is a tool for defining and running multi-container Docker applications using a single YAML file.
Key Concept: Compose lets you define your entire application stackβweb servers, databases, caches, queuesβin one file and launch everything with one command.
# Start all services with one command
docker compose up -d
What is the primary purpose of Docker?
| Aspect | Docker | Docker Compose |
|---|---|---|
| Scope | Single container management | Multi-container orchestration |
| Configuration | Command-line arguments | YAML file (declarative) |
| Networking | Manual network setup | Automatic network creation |
| Best For | Simple apps, single services | Complex multi-service stacks |
Important: Docker Compose uses Docker under the hood. It's not a replacementβit's an abstraction layer that simplifies managing multiple containers.
Let's compare how you'd run a typical three-tier blog application (web + database + cache).
docker network create blog-net
docker run -d --name db ...
docker run -d --name cache ...
docker run -d --name web ...
services:
web: ...
db: ...
cache: ...
Real Impact: Docker Compose automatically creates networks, manages startup order with depends_on, and lets services reference each other by name. What takes 10+ lines of Docker commands becomes 15 lines of declarative YAML.
When running multiple related containers (e.g., web app + database + cache), what is a key advantage of using Docker Compose?
Your team is building a web app with React frontend, Node.js API, PostgreSQL database, and Redis cache. Which tool is most appropriate for local development?
Preserve data even when containers restart
Manage configs and secrets safely
Ensure services are ready before connecting
Real Impact: These features eliminate hours of manual setup, making complex environments reproducible in seconds.
What does the depends_on field accomplish in a docker-compose.yml file?
Industry Insight: According to Docker's 2023 survey, teams using Compose report 3x faster onboarding for new developers.
# Build & run
docker build -t app:v1 .
docker run -d -p 8080:80 app:v1
# Manage
docker ps
docker logs name
docker stop name
docker rm name
# Build & run
docker compose up -d
docker compose up --build
# Manage
docker compose ps
docker compose logs -f
docker compose down
Note: Modern Docker uses docker compose (no hyphen). The older docker-compose command is being phased out.
You've learned the fundamentals of Docker and Docker Compose! Now it's time to demonstrate your understanding.
Which file format does Docker Compose use to define multi-container applications?
You're joining a new team with an app that has 7 microservices. What's the best way to get the dev environment running on your laptop?
What is the relationship between Docker and Docker Compose?
Which scenario is BEST suited for using standard Docker commands rather than Docker Compose?
In a docker-compose.yml file, what is the primary benefit of defining volumes for your database service?