Docker – set a custom data folder

The default docker data folder is /var/lib/docker. This can be changed to another folder with the following steps. These all need to executed as root or with sudo.

Stop Docker on your computer

service docker stop

Create a new docker daemon config

nano /etc/docker/daemon.json

Add the following text and replace /mnt/docker with the path you want to use as the docker data folder

{ 
   "data-root": "/mnt/docker"
}

Save your changes and close the file.

(Optional) If you want to move the existing data to the new folder

cp -rp /var/lib/docker/* "/mnt/docker/"

Start Docker

service docker start

Remove the old folder if everything is working

rm -rf /var/lib/docker

Leave a Reply

Your email address will not be published. Required fields are marked *