By default docker on linux uses /var/lib/docker as its data directory (in docker parlance, "data-root"). This can be inconvenient for those of us whose /var is located on a boot drive with only a modest amount of space. After installing docker I always relocate its data directory to a bigger volume. Assuming that volume is named "data1", here's the procedure:
- Shut down docker and containerd,
systemctl stop docker; systemctl stop containerd
. - Create a /etc/docker/daemon.json file with the following contents:
{
"data-root": "/data1/docker"
}
- Use rsync to copy the data from the old to new locations:
rsync -a /var/lib/docker /data1
- Restart containerd and docker again,
systemctl start containerd; systemctl start docker
References:
"Control Docker with systemd". Docker Docs, https://docker-docs.netlify.app/config/daemon/systemd/.
"Relocating the Docker root directory". IBM Z Operational Log and Data Analytics, https://www.ibm.com/docs/en/z-logdata-analytics/5.1.0?topic=compose-relocating-docker-root-directory.