How to Change Docker Data Root Path on Windows 10

Raymond Raymond event 2022-12-04 visibility 16,024 comment 2
more_vert

By default, Docker Desktop stores all images and container data in folder C:\ProgramData\Docker. This can lead to massive space consumption in your system drive. The space can be quickly consumed if you run containers like Windows 10 or Windows 11. To avoid this issue, you can try to change Docker Desktop root  data path.

Tested version

The solution is tested with the following engine:

  • Docker Desktop for Windows: v4.15.0
  • Docker Engine version: v20.10.21

Approach 1 - use UI

Follow the steps below to change data folder:

warningtjos Alert - This approach doesn't work on my Windows 10.
  1. Open Docker Desktop window.
  2. Go to Settings
  3. Click tab  Docker Engine.
  4. In the JSON settings, add a new property data-root with values of the location for storing docker data as the following screenshot shows:
    20221204115217-image.png
  5. Click button Apply & restart.

Approach 2 - Update config file directly

If the above approach doesn't work, try the following steps:

  • Stop Docker Desktop.
  • Go to your user home folder on Windows, for example, C:\Users\username\ or %USERPROFILE%.
  • Go to folder .docker.
  • Open or create file daemon.json.
  • Add data root config into the above mentioned file:
    {
      "data-root": "E:\\Docker\\ProgramData",
      "experimental": false,
    }

    *Change the highlighted path to yours accordingly.

Switch to Windows Containers

You may need to switch to Windows Containers if you are using Linux containers. You can achieve this by following these steps:

  • Open a Command Prompt with Administrative rights
  • Change directory to `C:\Program Files\Docker\Docker`.
  • Run command resources\dockerd.exe. It prints out the following logs:
    time="2022-12-05T11:33:32.418794600+11:00" level=info msg="Starting up"
    time="2022-12-05T11:33:32.435137700+11:00" level=info msg="Windows default isolation mode: hyperv"
    time="2022-12-05T11:33:32.856620000+11:00" level=info msg="Loading containers: start."
    time="2022-12-05T11:33:32.857876500+11:00" level=info msg="Restoring existing overlay networks from HNS into docker"
    time="2022-12-05T11:33:34.999317000+11:00" level=info msg="Loading containers: done."
    time="2022-12-05T11:33:35.000407400+11:00" level=info msg="Docker daemon" commit=03df974 graphdriver(s)=windowsfilter version=20.10.20
    time="2022-12-05T11:33:35.001475000+11:00" level=info msg="Daemon has completed initialization"
    time="2022-12-05T11:33:35.122102600+11:00" level=info msg="API listen on //./pipe/docker_engine_windows"
  • Open another Command Prompt with Administrative rights.
  • Type command C:\Program Files\Docker\Docker\DockerCli.exe -SwitchDaemon
  • Verify the results by running command docker version:
    Client:
     Cloud integration: v1.0.29
     Version:           20.10.21
     API version:       1.41
     Go version:        go1.18.7
     Git commit:        baeda1f
     Built:             Tue Oct 25 18:08:16 2022
     OS/Arch:           windows/amd64
     Context:           default
     Experimental:      true
    
    Server: Docker Engine - Community
     Engine:
      Version:          20.10.21
      API version:      1.41 (minimum version 1.24)
      Go version:       go1.18.7
      Git commit:       3056208
      Built:            Tue Oct 25 18:03:04 2022
      OS/Arch:          windows/amd64
      Experimental:     false

To start dockerd (Docker Daemon) automatically, make sure docker system services (Docker Engine) is setup correctly:

20221205105600-image.png

"C:\Program Files\Docker\Docker\resources\dockerd.exe" --run-service --service-name docker -G docker-users --config-file C:\ProgramData\Docker\config\daemon.json

The service by default use the above command line. Make sure the daemon.json configuration file exists. And also change the config file to add data-root configuration property as the above example does.

Daemon issue

If you encounter this error - Error response from daemon: open \\.\pipe\docker_engine_windows: The system cannot find the file specified, try the following commands using PowerShell (Administrator mode):

Enable-WindowsOptionalFeature -Online -FeatureName $("Microsoft-Hyper-V", "Containers") -All

If the issue still exists, try uninstall Docker Desktop and downgrade to version 4.13.1.

*Credit: Error response from daemon: open \\.\pipe\docker_engine_windows: The system cannot find the file specified - Docker Desktop for Windows - Docker Community Forums

Other settings

To find out all the other supported settings, refer to official documentation: dockerd | Docker Documentation.

More from Kontext
comment Comments
V Vibs Agarwal

Vibs access_time 2 years ago link more_vert

I'm trying to use Windows containers (WSL2). I have tried your steps but its not working. 

Raymond Raymond

Raymond access_time 2 years ago link more_vert

The steps are for Docker Desktop for Windows and only for Windows containers.  Did you follow all the steps to update dockerd service and also uses the config file in another directory?


Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts