This can help prevent space issues with Linux instances!
"OSError: [Errno 28] No space left on device"
Before you get started, make sure to backup your files so that in case that anything goes wrong, you could revert back to a backup!
Once you have your backup in place, follow these steps here:
sudo systemctl stop docker
After that, make sure that Docker is not running with the following commands:
sudo systemctl status docker
If you see that Docker is not running, then you could proceed. Another way of checking if there are any Docker processes is by using the ps command:
ps faux | grep -i docker
/var/lib/docker/ Docker directory to the new location. Let’s say that we want to put the files in a folder called /home/docker. To do so, first create the folder:mkdir /home/docker
Then using the rsync command transfer the files over:
rsync -avxP /var/lib/docker/ /home/docker
Note: this might take a while depending on the size of your images. If your folder is too large you might want to run the rsync command in a screen session to avoid your connection being dropped and interrupting the transfer.
sudo nano /lib/systemd/system/docker.service
Find the following line:
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
And change it to:
ExecStart=/usr/bin/dockerd -g /home/docker -H fd:// --containerd=/run/containerd/containerd.sock
Then reload the systemd daemons:
sudo systemctl daemon-reload
And finally, start Docker:
systemctl start docker
Finally, to confirm if your images are being loaded from the new path, you can inspect one of your images:
Find an image id:
docker images
Inspect the image and look for the WorkDir:
docker inspect image_id | grep WorkDir
Ref: How to move the default /var/lib/docker to another...
Another alternative that worked on RHEL 9.4
To change the Docker directory in Red Hat Enterprise Linux (RHEL), you can create a systemd drop-in service file instead of modifying the .service file directly. Modifying the .service file could cause it to be overwritten during an update.
Here are the steps to change the Docker directory:
sudo systemctl stop dockersudo systemctl stop docker.socketsudo systemctl stop containerdsudo mkdir -p /new_dir_structuresudo mv /var/lib/docker /new_dir_structure/etc/docker/daemon.json with the following content:
{ "data-root": "/new_dir_structure/docker" }{
"runtimes": {
"nvidia": {
"args": [],
"path": "nvidia-container-runtime"
}
},
"data-root": "/home/docker"
}
sudo systemctl start dockerdocker info -f '{{ .DockerRootDir}}'The standard data directory for Docker is /var/lib/docker, which can grow large quickly.