Sometimes you need to arrange in a different way your file system. For example because you have a particular partitioning or maybe you are using an encrypted partition. Infact you may want your docker data to be inside an encrypted location. This may be strongly useful for running containers which manage secret data or keys. This is how to do.
Let’s imagine that your encrypted partition is mounted on /opt . First of all, fully stop your docker daemon
sudo systemctl stop dockerCreate a new directory dedicated to docker inside the mountpoint of your encrypted filesystem
sudo mkdir -p /opt/new_dirNow define the data root for docker, by changing the daemon.json file.
sudo vim /etc/docker/daemon.jsonModify or add the following json structure
{
"data-root": "/opt/new_dir/docker"
}Checking if all went fine
massmux@augustus:~$ docker info -f '{{ .DockerRootDir}}'
/opt/new_dir/dockerthat’s it, all is fine and you can start again the docker daemon. Enjoy and please leave a comment below with your opinions.
For all your VPS, Domains and hosting needs, please consider https://denali.eu



Thanks for the tip, very helpful