--data-root is the path where persisted data such as images, volumes, and cluster state are stored.
and
--exec-root is the path where the container state is stored. The default value is /var/run/docker. Specify the path for your running daemon here.
So if you want to move both your containers and images (and the other stuff), you have to set both of these parameter.
You can also create a simple link where Docker expects its folder to redirect to the desired place.
It is described here and lead to the same result. It looks "dirty" but in the end it looks more stable than the first solution.
Working with WSL 2 engine (for Windows Home and Family Editions)
"D:\\Docker\\data-root" value as suggested by Miguel will crash Docker because it has to be a WSL folder.
However, Docker create a specific WSL distro which contains your docker data, and you can move it. This does not require to modify dockerd parameters.
On Docker v19.03.8 for Windows, I added the graph parameter to my config, and it worked for me, but apparently, this parameter is deprecated and we should now use data-root instead. The default value for data-root is c:\programdata\docker. Beware that in the JSON configuration file the backslashes need to be escaped.
For Unix containers, the path for images can be changed by Docker Desktop interface, at settings form. But if you use the windows containers feature then a second service is installed, the "Docker Engine". To change the image folder for this service do the following steps:
1) Get the path to the config file.
Go to Administrative tools->Services.
Check docker demon command line for service "Dock Engine"
2) Edit the config file daemon.json and add the data-root property.Property value should point to desired location. Should look something like this. Check this for information on json structure.
If necessary, give permissions for the running account to access the folder.
3) restart the service.
If doesn't start, check eventlog for possible errors.
Previous configured data in c:\ProgramData\Docker will be lost when you change the install location.
It’s like a new install to a new location. (images, containers, etc). All sub folders will be created again.
To keep the minimum on system drive do this on a fresh install.
I am not 100% sure about this solution, but so far, docker is working fine and system drive occupation is slim.
This answer is more an addition at Jean-François Beauchamp's answer :
You can find full documentation about this config file on Docker's documentation.
It is stated :
and
So if you want to move both your containers and images (and the other stuff), you have to set both of these parameter.
You can also create a simple link where Docker expects its folder to redirect to the desired place.
It is described here and lead to the same result. It looks "dirty" but in the end it looks more stable than the first solution.
Working with WSL 2 engine (for Windows Home and Family Editions)
"D:\\Docker\\data-root"
value as suggested by Miguel will crash Docker because it has to be a WSL folder.However, Docker create a specific WSL distro which contains your docker data, and you can move it. This does not require to modify dockerd parameters.
To move docker's WSL distro
The
X:\wslStore
param is the path where you want to "mount" your Distro, something likeD:\Docker\data-root
On Docker v19.03.8 for Windows, I added the
graph
parameter to my config, and it worked for me, but apparently, this parameter is deprecated and we should now usedata-root
instead. The default value fordata-root
isc:\programdata\docker
. Beware that in the JSON configuration file the backslashes need to be escaped.Find other way to do it based on this post.
For Unix containers, the path for images can be changed by Docker Desktop interface, at settings form. But if you use the windows containers feature then a second service is installed, the "Docker Engine". To change the image folder for this service do the following steps:
1) Get the path to the config file. Go to Administrative tools->Services. Check docker demon command line for service "Dock Engine"
The command line is something like
2) Edit the config file
daemon.json
and add the data-root property.Property value should point to desired location. Should look something like this. Check this for information on json structure.}
If necessary, give permissions for the running account to access the folder.
3) restart the service. If doesn't start, check
eventlog
for possible errors.Previous configured data in c:\ProgramData\Docker will be lost when you change the install location. It’s like a new install to a new location. (images, containers, etc). All sub folders will be created again.
To keep the minimum on system drive do this on a fresh install.
I am not 100% sure about this solution, but so far, docker is working fine and system drive occupation is slim.