Some of my environments are docker based. The filesystem layout mostly does not fit to the docker default of using
/var/lib/docker to store all data-intense information.
As I learned now a second time how to change the settings in CentOS without having problems during updates and avoid manual steps at all, I write it down for documentation and the future me. The following steps are needed.
Stop Docker to move the data and change configuration files.
$ systemctl stop docker
Add storage to your system, mount that and make it mount on reboot. We assume that
/data/docker is used. The next step now, overwrite the data directory in the Docker system files and make this permanent.
The current startup parameter can be checked with
systemctl cat docker | grep ExecStart - next add the new data directory to the
$ systemctl cat docker | grep ExecStart ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
systemctl edit docker is the fastest way to create all necessary data structures to overwrite the defaults. The following will first overwrite
ExectStart with an empty string, the second line adds the new data location.
[Service] ExecStart= ExecStart=/usr/bin/dockerd -g /data/docker -H fd:// --containerd=/run/containerd/containerd.sock
The next step is to copy the current content of
/var/lib/docker to the new location. I have used the following rsync but other options are posible.
$ rsync -aqxP /var/lib/docker/ /data/docker/
Next start Docker with the new data location and check if all is running from the new location
$ systemctl start docker && journalctl -u docker
The last step - delete the content of
/var/lib/docker/ do free up space on the disk.