મૂળભૂત service definitions ની બહાર, Docker Compose વાસ્તવિક-વિશ્વ ઉપયોગ માટે features પ્રદાન કરે છે — environment management, health checks, dependency conditions, profiles, networks/volumes configuration, scaling, અને overrides — જે તેને development અને જટિલ stacks માટે વધુ શક્તિશાળી બનાવે છે।
Environment અને configuration
services:
app:
build: .
env_file: .env # load environment variables from a file
environment:
- NODE_ENV=production
ports:
- "${PORT:-3000}:3000" # variable substitution with a default
Compose .env files, environment variables, અને variable substitution (${VAR:-default}) સમર્થન કરે છે લવચક, environment-specific configuration માટે।
Health checks અને dependency conditions
services:
db:
image: postgres:16
healthcheck: # define how to check the service is healthy
test: ["CMD", "pg_isready", "-U", "postgres"]
interval: 5s
retries: 5
app:
build: .
depends_on:
db:
condition: service_healthy # wait until db is HEALTHY (not just started)
depends_on with condition: service_healthy (plus a healthcheck) એક service ને নিশ્ચિત કરે છે કે તે તેની dependency ની રાહ જોય જ્યાં સુધી તે ખરેખર તૈયાર હોય — માત્ર શરૂ નહીં — સામાન્ય "app database તૈયાર થાય તે પહેલાં શરૂ થાય" race ને ઉકેલે છે।
Profiles, overrides, અને scaling
PROFILES → group optional services (e.g. only start "debug" tools when wanted):
docker compose --profile debug up
OVERRIDE files → docker-compose.override.yml auto-merges (dev overrides);
or -f compose.yml -f compose.prod.yml for environment-specific configs
SCALING → docker compose up --scale worker=3 (run 3 instances of a service)
NAMED VOLUMES & NETWORKS → declare and configure them at the top level
તે શા માટે મહત્વપૂર્ણ છે
Advanced Docker Compose features ને સમજવું real-world development અને complex stacks માં Compose નો અસરકારક ઉપયોગ માટે મૂલ્યવાન છે, મૂળભૂત service definitions પર આધારિત। ").split(
