This script helps you safely migrate Docker data directory (default: /var/lib/docker) to a new location.
It performs strict pre-checks, ensures sufficient disk space, validates configuration files, and automatically stops/starts Docker.
- Project homepage: reshub-cn/docker-data-move.sh
- Official website: www.reshub.cn
- Preflight safety checks (root, commands, SELinux, disk space, JSON config validity).
- Supports Debian/Ubuntu, CentOS/RHEL, Alpine.
- Uses
rsync -aHAX --numeric-ids --deleteto preserve all data (including permissions, extended attributes, hard links). - Automatic backup of the old Docker data directory.
- Automatically updates
/etc/docker/daemon.jsonwith the newdata-root. - Auto-installation of
jqandrsync(if possible).
# Download the script
curl -sSL https://raw.githubusercontent.com/reshub-cn/docker-data-move.sh/main/docker-move.sh -o docker-move.sh
chmod +x docker-move.sh
# Run (example: migrate to /data1/docker)
sudo ./docker-move.sh /data1/dockerBy default, the new directory must be empty.
If you want to allow migrating into a non-empty directory, set:
ALLOW_NONEMPTY=1 sudo ./docker-move.sh /data1/docker- Always run as root (
sudorequired). - Ensure target disk has enough space. The script checks if at least
max(used*110%, used+2GiB)is available. - If SELinux is enforcing, you must relabel the new directory:
semanage fcontext -a -t container_var_lib_t "/data1/docker(/.*)?" restorecon -Rv /data1/docker - Old data is backed up as
/var/lib/docker.bak.TIMESTAMP.
After Docker restarts, check:
docker info | grep "Docker Root Dir"Output should point to your new path.
MIT License © 2025 ResHub