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

الفصل 2الاسم في الدورة: Running containers

Run and manage containers

The daily container commands: run a container (in the foreground or background), look at it, read its logs, get a shell inside, limit its resources, stop and remove it. Docker and Podman use the same commands — swap docker for podman.

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

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

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

2.1

Run a container

docker run = pull the image if needed + create + start.

docker run --rm hello-world
docker run --rm -it ubuntu:24.04 bash
docker run -d --name web -p 8080:80 nginx:1.27
docker run -d --name app -e APP_ENV=prod -e TZ=Asia/Riyadh --restart unless-stopped myorg/app:1.4
curl -I http://localhost:8080
OptionMeaning
-dDetached: run in the background
-itInteractive terminal
--rmRemove the container when it stops
--nameA fixed name
-p HOST:CONTAINERPublish a port (127.0.0.1:8080:80 = only local)
-e VAR=value, --env-file FILEEnvironment variables
--restartno, on-failure, always, unless-stopped

2.2

Look at running containers

List, inspect and watch containers.

docker ps
docker ps -a --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'
docker inspect web --format '{{.State.Status}} {{.NetworkSettings.IPAddress}}'
docker top web
docker stats --no-stream
docker port web

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

2.3

Read logs and get a shell

Containers log to stdout/stderr; docker logs shows it. docker exec runs a command inside a running container.

docker logs web
docker logs -f --tail 50 --since 10m web
docker exec -it web sh
docker exec web nginx -t
docker cp web:/etc/nginx/nginx.conf ./nginx.conf

في العمل

Many small images have no bash — use sh. Very small ones (distroless) have no shell at all: use docker cp and docker logs, or a debug container.

2.4

Limit resources

Without limits, one container can use all CPU and memory of the host.

docker run -d --name worker --memory 512m --memory-swap 512m --cpus 1.5 --pids-limit 200 myorg/worker:2.0
docker update --memory 1g --memory-swap 1g worker
docker stats worker --no-stream
OptionLimits
--memory, --memory-swapRAM (and RAM + swap) — over it, the process is killed (OOM)
--cpusCPU time (1.5 = one and a half cores)
--pids-limitNumber of processes (stops fork bombs)
--ulimit nofile=1024:2048Open files

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

2.5

Stop, start and remove

Stop sends SIGTERM (then SIGKILL after 10 s). Remove deletes the container and its writable layer.

docker stop web
docker start web
docker restart web
docker kill -s HUP web
docker rm web
docker rm -f $(docker ps -aq --filter status=exited)
docker container prune -f

تذكّر

A container stops when its main process (PID 1) ends. A container that exits at once usually has a start command that finishes or fails — read docker logs.

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

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