الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

الفصل 8الاسم في الدورة: Docker Compose

Run multi-container apps with Compose

Compose describes a whole app — web, API, database, cache — in one compose.yaml file: images, ports, volumes, networks, variables and start order. One command starts or stops everything. It is perfect for development, tests and small single-host deployments.

  • 5 الدروس
  • 1 الأوامر

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

$ مستخدم عادي# بصلاحية root (أو مع sudo)

8.1

Write a compose file

Each service is a container; Compose creates a network where services find each other by name.

compose.yaml
services:
  web:
    image: nginx:1.27
    ports: ["8080:80"]
    volumes:
      - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
    depends_on:
      api:
        condition: service_healthy
  api:
    build: ./api
    environment:
      DATABASE_URL: postgres://shop:${DB_PASSWORD}@db:5432/shop
    healthcheck:
      test: ["CMD", "curl", "-fs", "http://localhost:8080/health"]
      interval: 10s
      retries: 5
    depends_on:
      db:
        condition: service_healthy
  db:
    image: postgres:16
    environment:
      POSTGRES_USER: shop
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_DB: shop
    volumes: [pgdata:/var/lib/postgresql/data]
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U shop"]
      interval: 5s
      retries: 10
volumes:
  pgdata:
.env
DB_PASSWORD=change-me-locally

8.2

Run the app

docker compose (or podman compose) works on the whole project.

docker compose up -d
docker compose ps
docker compose logs -f api
docker compose exec db psql -U shop
docker compose up -d --build api
docker compose pull && docker compose up -d
docker compose down
docker compose down -v
docker compose config
CommandDoes
up -dCreate and start everything in the background
up -d --buildRebuild images first
down / down -vStop and remove (and with -v delete volumes!)
configShow the final file with variables filled in

الأوامر في هذا الدرس

8.3

Wait for real readiness

depends_on alone only waits for the container to start. With condition: service_healthy, Compose waits for the health check to pass.

8.4

Use files per environment

A base file plus an override file per environment.

docker compose -f compose.yaml -f compose.prod.yaml up -d
docker compose --profile debug up -d
  • compose.override.yaml is read automatically in development.
  • Profiles start extra services only when asked (for example a debug tool).

انتبه

The .env file is for local values. Never commit real production secrets in it; use a secret store or Compose secrets:.

الأوامر في هذا الدرس

8.5

Know when to move on

Compose runs on one host. When you need many hosts, self-healing, rolling updates and autoscaling, move to Kubernetes — see CKA. Tools like Kompose can turn a compose file into Kubernetes manifests as a start.

كل الأوامر في هذا الفصل