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

الفصل 6الاسم في الدورة: Persisting data

Keep data with volumes and bind mounts

A container's own file layer disappears with the container. Databases, uploads and logs need storage that lives longer: named volumes (managed by the engine), bind mounts (a host folder), or tmpfs (memory only).

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

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

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

6.1

Choose the storage type

Pick by who manages the data and where it lives.

TypeWhereGood for
Named volumeManaged by Docker/Podman (/var/lib/docker/volumes)Databases, app data
Bind mountAny host folderConfig files, source code in development
tmpfsRAM, gone at stopSecrets at run time, caches

6.2

Use named volumes

Create a volume and mount it; the data survives docker rm and image updates.

docker volume create pgdata
docker run -d --name db -e POSTGRES_PASSWORD_FILE=/run/secrets/pg -v pgdata:/var/lib/postgresql/data postgres:16
docker volume ls
docker volume inspect pgdata --format '{{.Mountpoint}}'
docker rm -f db
docker run -d --name db -v pgdata:/var/lib/postgresql/data postgres:16

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

6.3

Use bind mounts

Mount a host folder or file into the container — read-only when the container should not change it.

docker run -d --name web -p 8080:80 -v /srv/site:/usr/share/nginx/html:ro nginx:1.27
docker run -d --name web2 --mount type=bind,src=/srv/site,dst=/usr/share/nginx/html,readonly nginx:1.27
podman run -d --name web3 -p 8081:8080 -v /srv/site:/var/www/html:Z registry.access.redhat.com/ubi10/httpd-24

تذكّر

On RHEL with SELinux, add :Z (private) or :z (shared) to bind mounts, or the container gets "Permission denied".

6.4

Back up and restore a volume

Use a small helper container that mounts the volume and writes a tar file.

docker run --rm -v pgdata:/data -v "$PWD":/backup alpine tar czf /backup/pgdata-$(date +%F).tgz -C /data .
docker run --rm -v pgdata:/data -v "$PWD":/backup alpine sh -c "cd /data && tar xzf /backup/pgdata-2026-10-27.tgz"

في العمل

For databases, prefer the database's own dump tool (pg_dump, mysqldump) — a file copy of a running database can be inconsistent.

6.5

Use tmpfs and read-only containers

A read-only root file system stops attackers from changing files; tmpfs gives the app the few writable places it needs.

docker run -d --name api --read-only --tmpfs /tmp:rw,size=64m -v api-data:/data myorg/api:2.0

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

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