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

docker

Build, ship and run containers — the most used container tool in CI pipelines and on developer laptops.

المستوى
خدمة DevSecOps
المجموعة
الحاويات و Kubernetes
يحتاج root
للتغييرات
الحزمة
docker-ce

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

ماذا يفعل

Docker packs an app with everything it needs into an image and runs it as an isolated container. The docker CLI talks to the dockerd daemon (service docker.service). Images come from registries (Docker Hub, GitHub ghcr.io, Azure ACR). Docker Compose (docker compose) runs several containers from one YAML file.

On RHEL the built-in tool is podman (same commands, no daemon, rootless by default). Docker CE is installed from Docker's own repository. Users in the docker group are root on the host — keep that group small.

طريقة الكتابة

docker COMMAND [OPTIONS] [ARGS]
docker compose [-f compose.yaml] up|down|ps|logs

الأجزاء الرئيسية

Main commands

run
Create and start a container from an image.
ps [-a]
List running (all) containers.
build -t NAME:TAG .
Build an image from a Dockerfile.
images / image ls
List local images.
pull / push
Download / upload an image.
exec -it C sh
Run a command inside a running container.
logs [-f] C
Show container output.
stop / start / restart / rm C
Container life cycle.
inspect OBJ
Show low-level JSON details.
volume / network
Manage volumes and networks.
compose
Multi-container apps from compose.yaml.
system df / system prune
Disk use / clean up.
login / logout REGISTRY
Log in to a registry.
buildx
Advanced builds (multi-platform, cache).
scout
Check images for known CVEs (Docker Scout).

الخيارات 15

الأكثر استخدامًا

docker run options

-d
Run in the background.
-it
Interactive with a terminal.
--name NAME
Name the container.
-p HOST:CONT
Publish a port.
-v SRC:DST[:ro]
Mount a volume or a host folder.
-e KEY=VALUE / --env-file FILE
Set environment variables.
--rm
Remove the container when it exits.
--restart unless-stopped
Restart policy.
--network NET
Join a network.
-u UID:GID
Run as this user.
--read-only
Read-only root file system.
--cap-drop ALL / --cap-add CAP
Remove / add Linux capabilities.
--security-opt no-new-privileges
Block privilege escalation.
--memory 512m / --cpus 1
Resource limits.
--health-cmd CMD
Health check command.

أمثلة 11

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

  1. 1Install Docker CE on RHEL and run a test

    dnf config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo
    dnf install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
    systemctl enable --now docker
    docker run --rm hello-world
  2. 2Run a web server in the background

    docker run -d --name web -p 8080:80 --restart unless-stopped nginx:1.27
    docker ps
    curl -I http://localhost:8080
  3. 3Look inside and read the logs

    docker logs -f --tail 50 web
    docker exec -it web sh
    docker inspect -f '{{.NetworkSettings.IPAddress}}' web
  4. 4Build and tag an image

    cat Dockerfile
    FROM python:3.12-slim
    WORKDIR /app
    COPY requirements.txt .
    RUN pip install --no-cache-dir -r requirements.txt
    COPY . .
    USER 1001
    CMD ["python", "app.py"]
    docker build -t ghcr.io/s0sta/shop:1.4.0 .
  5. 5Push to a registry

    echo "$GHCR_TOKEN" | docker login ghcr.io -u s0sta --password-stdin
    docker push ghcr.io/s0sta/shop:1.4.0
  6. 6Run a hardened container

    docker run -d --name api --read-only --tmpfs /tmp -u 1001:1001 --cap-drop ALL --security-opt no-new-privileges --memory 256m --cpus 0.5 -p 8080:8080 ghcr.io/s0sta/shop:1.4.0
  7. 7Keep data in a named volume

    docker volume create pgdata
    docker run -d --name db -e POSTGRES_PASSWORD_FILE=/run/secrets/pg -v pgdata:/var/lib/postgresql/data postgres:16
  8. 8Run a full stack with Compose

    cat compose.yaml
    services:
      web:
        image: ghcr.io/s0sta/shop:1.4.0
        ports: ["8080:8080"]
        depends_on: [db]
      db:
        image: postgres:16
        volumes: [pgdata:/var/lib/postgresql/data]
    volumes:
      pgdata: {}
    docker compose up -d
    docker compose ps
    docker compose logs -f web
    docker compose down
  9. 9Build for two CPU types

    docker buildx build --platform linux/amd64,linux/arm64 -t ghcr.io/s0sta/shop:1.4.0 --push .
  10. 10Check an image for CVEs

    docker scout cves ghcr.io/s0sta/shop:1.4.0
    trivy image ghcr.io/s0sta/shop:1.4.0
  11. 11Free disk space

    docker system df
    docker system prune -a --volumes

انتبه

  • The docker group = root on the host. Prefer rootless Docker or podman.
  • Never put secrets in a Dockerfile (ENV, COPY .env): they stay in the image layers.
  • -p 8080:80 opens the port on all addresses and passes around firewalld rules; use -p 127.0.0.1:8080:80 for local-only.
  • Pin image tags (better: digests), never use latest in production.

الملفات

/etc/docker/daemon.json
Daemon settings (log driver, registries, userns-remap).
/var/lib/docker/
Images, containers, volumes.
~/.docker/config.json
Registry logins.
/var/run/docker.sock
The daemon API socket (root access!).

نصائح للحفظ

  • Add a .dockerignore (with .git, .env, node_modules) to keep images small and secret-free.
  • Use multi-stage builds and slim or distroless base images.

رموز الخروج

0Success.
125Docker daemon error.
126The command in the container cannot run.
127The command in the container was not found.

الدليل الكامل

هذه الصفحة تشرح الأمر بكلمات بسيطة. الدليل الأصلي فيه كل التفاصيل.

في الطرفية: man docker