Operations 6 min read

Master Docker Data Persistence, Networking, and Resource Limits: Practical Guide

This guide explains Docker's three data persistence methods (volumes, bind mounts, tmpfs), demonstrates practical examples, details the various network modes (bridge, host, none, container, custom), and shows how to apply resource limits such as memory and CPU constraints to containers.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Docker Data Persistence, Networking, and Resource Limits: Practical Guide

Docker Data Persistence Methods

Docker provides three ways to mount host data into containers: volumes, bind mounts, and tmpfs.

volumes : Docker-managed storage under /var/lib/docker/volumes, recommended for persisting data.

bind mounts : Mount any host directory or file into the container.

tmpfs : Stores data in host memory, not written to disk, useful for non‑persistent data and performance.

docker volume create nginx_vol
ls /var/lib/docker/volumes/nginx_vol/

Data is stored in the _data directory.

Example 1 – Using volumes

docker run -d --name nginx-ceshi -p 888:80 --mount -v nginx-ceshi:/usr/share/nginx/html nginx
# or
docker run -d --name nginx-ceshi -p 888:80 --mount src=nginx-ceshi,dst=/usr/share/nginx/html nginx
docker inspect nginx-ceshi

After creating the container you can see the persisted data directory.

cd /var/lib/docker/volumes/nginx-ceshi/_data
echo "hello world nginx" > index.html
# Access http://<host>:888/ to verify persistence

Example 2 – Bind mounts

docker run -d -it --name=nginx-test --mount type=bind,src=/app/wwwroot,dst=/usr/share/nginx/html/ nginx
docker run -d -it --name=nginx-test -v /root/html:/usr/share/nginx/html/ nginx

Notes: -v with an absolute path creates a bind mount; -v with a name creates a volume. Bind source must exist; the container’s mount point hides existing files.

Docker Network Modes

bridge

-net=bridge – default mode, Docker creates a docker0 bridge and attaches containers.

host

-net=host – container shares the host’s network namespace, no separate network interface.

none

-net=none – container gets an isolated network namespace but no network configuration; user must configure manually.

container

-net=container:Name/ID – shares the network namespace of another container while keeping other namespaces isolated.

Example:

docker run -itd --name zd -p 99:80 busybox
docker run -itd --name nginx-zd --net container:zd nginx
curl 192.168.106.100:99   # nginx uses zd’s network

Custom networks behave like bridge but provide internal DNS for container‑to‑container name resolution.

docker network create zf-100

Docker Resource Limits

Docker can limit container resources to prevent exhausting the host and to improve isolation.

Common options:

-m, --memory            Max memory the container can use
--memory-swap           Amount of memory+swap allowed
--oom-kill-disable      Disable OOM killer
--cpus                  Number of CPUs the container can use
--cpuset-cpus           Specific CPU cores (e.g., 0-3)
--cpu-shares            Relative CPU weight

Examples:

docker run -d --name web03 --memory="500m" --memory-swap="600m" --oom-kill-disable nginx
docker stats --no-stream web03   # view memory usage
docker run -d --name web01 --cpus="1" nginx   # limit to one CPU
docker run -d --name web01 --cpus=".5" nginx   # limit to 50% CPU
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DockerData PersistenceContainersNetwork Modesresource-limits
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.