هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
Choose the storage type
Pick by who manages the data and where it lives.
| Type | Where | Good for |
|---|---|---|
| Named volume | Managed by Docker/Podman (/var/lib/docker/volumes) | Databases, app data |
| Bind mount | Any host folder | Config files, source code in development |
| tmpfs | RAM, gone at stop | Secrets at run time, caches |
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:16Use 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".
Back up and restore a volume
Use a small helper container that mounts the volume and writes a tar file.
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