There are few options to change where Docker images and volumes are stored. You can make /var/lib/docker
a mount point to some new partition; or symbol link var/lib/docker
to a path on certain filesystems. This approach below involves updating docker.service
in systemd with the new path.
Risk of this approach is from time to time, when Docker is upgraded, there is a chance that the updated
docker.service
file gets reverted to default settings. In that case, you will not see the current images and volumes and will have to update the file again
$ sudo systemctl stop casaos*.service
$ sudo systemctl status casaos.service
○ casaos.service - CasaOS Service
Loaded: loaded (/etc/systemd/system/casaos.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Sat 2022-08-13 12:58:08 EDT; 6min ago
Process: 9812 ExecStart=/usr/bin/casaos -c /etc/casaos.conf (code=killed, signal=TERM)
Main PID: 9812 (code=killed, signal=TERM)
CPU: 2.181s
$ sudo systemctl stop docker.*
$ sudo systemctl status docker.service
○ docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Sat 2022-08-13 13:07:59 EDT; 2s ago
TriggeredBy: ○ docker.socket
Docs: https://docs.docker.com
Process: 565 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock (code=exited, status=>
Main PID: 565 (code=exited, status=0/SUCCESS)
CPU: 1min 54.225s
$ sudo systemctl status docker.socket
○ docker.socket - Docker Socket for the API
Loaded: loaded (/lib/systemd/system/docker.socket; enabled; vendor preset: enabled)
Active: inactive (dead) since Sat 2022-08-13 13:07:59 EDT; 5s ago
Triggers: ● docker.service
Listen: /run/docker.sock (Stream)
CPU: 1ms
$ sudo mkdir -p /path/to/new/location
In this example, it is
/path/to/new/location
. Make sure it is changed to the actual preferred path.
root
user or under sudo
privilege, update /lib/systemd/system/docker.service
to include --data-root /path/to/new/location
parameter in the line starts with ExecStart=
. such as use sudo vim /lib/systemd/system/docker.service
to update the configure.For example, if previously the line looks like
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Then after the update it should look like
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --data-root /path/to/new/location
/var/lib/docker
to the new path.$ sudo rsync -avxP /var/lib/docker/ /path/to/new/location
In case something goes wrong and things need to be reverted, we do not actually move the content. Instead we use
rsync
to copy content over to the new path.
$ sudo reboot
/var/lib/docker/*
to reclaim some storage space.$ sudo rm -rf /var/lib/docker/*
If the command above does not clean the folder completely, try
sudo su
followed byrm -rf /var/lib/docker/*
https://discord.com/channels/884667213326463016/1163133627291422770/1163133627291422770