Notes - Changing the default Docker root directory
TIL you can change the default root dir for Docker. This is fucking rad.
I learned this watching this Raid Owl video about using Docker on a GL.iNet Slate 7 travel router.
The reason to do this is for devices with limited / storage and want to save the docker images and any unmapped volumes to a different location. Think the Lenovo 110S. This only has a 32GB eMMC flash drive for /. But it has a NVMe slot. We can change the Docker root dir to a dir on the NVMe and give a lot more breathing room.
New dir
First we need to make a new location. This folder has to be called docker.
sudo mkdir /mnt/test/docker
It is critical the final folder in the chain is named docker.
Set path
We are going to create a file in /etc/docker called daemon.json.
sudo nano /etc/docker/daemon.json
Now add this:
{
"data-root": "/new/path/docker"
}
Now restart Docker:
sudo systemctl restart docker
We can verify the new path with:
docker info | grep "Docker Root Dir"
We can also pull an image and then verify where it is stored:
docker pull nginx
docker image inspect ngnix
In the inspect we can see the location for the image under the "Data" section.