Free Up Docker Space: Relocate /var/lib/docker Using Symlinks & Config
When the root partition is too small for Docker's default storage at /var/lib/docker, you can reclaim space by moving the directory to a larger disk and updating Docker's storage path via symbolic links, daemon options, or systemd drop‑in files, ensuring the service continues to run smoothly.
Because the initial system partition is small, the root (/) partition cannot accommodate Docker's default storage located at /var/lib/docker. Over time this fills up, causing space issues. The article explains three ways to relocate Docker's storage to a larger disk.
1. Use a Symbolic Link
Check the current Docker root directory:
# Default storage location
$ sudo docker info | grep "Docker Root Dir"Stop Docker, move the directory, and create a symlink pointing to the new location:
# Stop Docker service
$ systemctl stop docker
# or
$ service docker stop
# Move the existing data
$ mv /var/lib/docker /data/docker
# Create the symbolic link
$ ln -sf /data/docker /var/lib/docker2. Specify the Storage Path with Daemon Options
Set the --graph (or -g) option in Docker’s configuration file to point to the new directory. The file location differs by distribution:
Ubuntu: /etc/default/docker CentOS: /etc/sysconfig/docker Example configurations:
# CentOS 6 (SELinux enabled)
OPTIONS=--graph="/data/docker" --selinux-enabled -H fd://
# CentOS 7 (modify systemd unit)
$ vi /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd --graph /new-path/docker
# Ubuntu (SELinux not enabled)
OPTIONS=--graph="/data/docker" -H fd://Reload the daemon and restart Docker:
# Reload systemd configuration
$ sudo systemctl daemon-reload
# Restart Docker
$ sudo systemctl restart docker.serviceFor Docker 1.12+ you can also edit or create /etc/docker/daemon.json:
{
"registry-mirrors": ["http://7e61f7f9.m.daocloud.io"],
"graph": "/new-path/docker"
}3. Create a Systemd Drop‑In File
Place a drop‑in file at /etc/systemd/system/docker.service.d/docker.conf to override the default ExecStart line:
# Define new storage location
$ sudo vi /etc/systemd/system/docker.service.d/docker.conf
[Service]
ExecStart=/usr/bin/dockerd --graph "/data/docker" --storage-driver=devicemapperAfter saving, reload and start Docker:
# Reload daemon
$ sudo systemctl daemon-reload
# Start Docker
$ sudo systemctl start dockerVerify the new root directory with docker info.
Reference
https://blog.51cto.com/forangela/1949947
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
