शुरुआती के लिए Docker Compose
Read this guide in: English · मराठी · हिंदी
Why Docker Compose चाहिए? क्योंकि app एक से ज़्यादा process हो तो developers और operations में problem आता है। Developers को web front और Redis cache चाहिए। Operations — server side — दो लंबी docker run lines, भूली networks, और cache hostname नहीं मिलता। Compose = एक docker-compose.yml: docker compose up stack जलाता है; docker compose down बंद करता है।
संक्षिप्त उत्तर
- Developer — laptop पर app + cache साथ।
- Operations — server-side person जिसे बिना folklore वही pair चलाना है।
- Problem — दो
docker run; drift; containers में गलत hostname। - Compose — एक YAML,
up,ps,logs,down। - Pocket: one file, one up, one down.
Language: English · मराठी · हिंदी
Problem? Suppose we are…
Suppose we are building Instagram (like updates)
Feed API को Redis cache। Developer दो commands से चलाता है। Container में localhost गलत। Operations EC2 पर laptop network दोहरा नहीं पाता।
Suppose we are working at Netflix and we are giving updates
छोटा local stack (app + cache) service name से बात करे। Compose वह network document करता है।
Suppose you are working in Infosys on a client project
Client operations एक file से lab stack शुरू चाहता है। Word doc की दो mystery docker run release day पर फेल।
Need Docker (EC2 install), Compose plugin।
One docker-compose.yml starts web and cache on a shared network; services talk by name with docker compose up.
Terminal-style teaching diagram: docker compose up -d and docker compose ps for web (published port) and cache (internal).
Compose कैसे जवाब देता है
docker compose version
mkdir composelab && cd composelab
cat > docker-compose.yml <<'EOF'
services:
web:
image: nginx:alpine
ports:
- "8080:80"
cache:
image: redis:alpine
EOF
docker compose up -d
docker compose ps
curl -I http://localhost:8080
docker compose down
Containers में service name cache — localhost नहीं। Cache/db के लिए अक्सर public ports: नहीं।
Ravindra Bagale's Tip
हर port internet पर मत खोलो। App cache से service name से बोले। याद रखो।
Learn it properly
Samajla ka? Why Compose = multi-container fight; Instagram / Netflix / Infosys “suppose”; एक YAML, up, down। Kubernetes से पहले यह practice करो।
Frequently asked questions
What is Docker Compose?
A tool that starts multi-container apps from one YAML file.
docker compose vs docker-compose?
Modern Docker uses the plugin form docker compose (space). The old hyphen binary may still exist.
Do I need Kubernetes for two containers?
No. Compose is enough for local and small server stacks.
Where do ports go?
ports: maps host:container. Internal service-to-service traffic often needs no public publish.
What is a service?
A named container definition in the Compose file (for example web or db).
How do I rebuild after code changes?
docker compose up -d --build to rebuild images then restart.