DockerAdvanced
Production-এর জন্য Docker
Restart policy, healthcheck, logging, resource limits ও হালকা production image — বাংলায়।
14টি অংশবাংলা ভাষায়
প্রোডাকশন মানে — container-কে বিশ্বস্ত, আত্মসচেতন ও নিরাপদ রাখা। মিলল কয়েকটি essentials:
Restart policy
compose.ymlyaml
yaml
services:
api:
image: my-api
restart: unless-stopped # crash হলে auto-restart| Policy | আচরণ |
|---|---|
no | কিছুই না (default) |
always | যেকোনো অবস্থায় restart |
unless-stopped | manually stop করা ছাড়া restart |
on-failure:5 | কথা ঠিকেই failure-এর পর restart (max 5) |
Healthcheck
compose.ymlyaml
yaml
services:
api:
build: .
healthcheck:
test: ["CMD", "node", "-e", "fetch('http://localhost:3000/health').then(r=>{if(!r.ok)process.exit(1)}).catch(()=>process.exit(1))"]
interval: 30s
timeout: 5s
retries: 3
start_period: 10sResource limits
Limit CPU/Memoryyaml
yaml
services:
api:
image: my-api
deploy:
resources:
limits:
cpus: "0.5" # সর্বোচ্চ ৫০% CPU
memory: 512M # সর্বোচ্চ 512 MB
reservations:
memory: 128MLogging
Default JSON logger-কে stdout-এ লিখুন। Docker সেই logs collector-এ নিয়ে যায় — docker logs, or cloud logging service (যেমন loki, cloudwatch)।
Rotate ও limityaml
yaml
services:
api:
image: my-api
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"Production checklist
- Multi-stage build + হালকা base image
- Non-root user (
USER node) NODE_ENV=productionset- Restart policy + healthcheck
- Secrets env-তে, না image-এ
.dockerignoreদিয়ে image ছোট করাdocker compose configদিয়ে file validatedocker scout/trivyদিয়ে vulnerability scan
compose config
docker compose config কমান্ড file validate ও resolved output দেখায় — deploy-এর আগে চালিয়ে নিন; করে syntax/আরো অন্য ভুল ধরা পড়বে।
শেষ প্যারায় নিজে practice করুন — কোড কপি করে নিজের এডিটরে চালিয়ে দেখুন।