नवशिक्यांसाठी 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 बंद करतो.
मित्रांनो, एक container पुरेसे नसेल तर आधी दोन-service ची fight पहा. मग YAML सोपा वाटेल.
थोडक्यात उत्तर
हे पाच पॉइंट्स लक्षात ठेवा:
- Developer — laptop वर app + cache एकत्र.
- Operations — server-side person ज्याला “फक्त एकाच्या डोक्यात असलेली” माहिती न वापरता तोच pair चालवायचा आहे.
- Problem — दोन
docker run; drift; containers मध्ये चुकीचा hostname. - Compose — एक YAML,
up,ps,logs,down. - लक्षात ठेवा: 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 reproduce करू शकत नाही.
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 ला फेल होतात.
आधी 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
समजलं का? 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.