Table of Contents

Docker Desktop for Windows

Purpose / Usage

Docker Desktop is a UI to help developers working with the Docker engine. It is not intended for use in production.

Configuration

Docker Daemon

%UserProfile%\.docker\daemon.json

Default configuration as of Docker Desktop for Windows version 4.30.0 (2024-06-06).

daemon.json
{
 "builder": {
  "gc": {
   "defaultKeepStorage": "20GB",
   "enabled": true
  }
 },
 "experimental": false
}

The default log driver is json-file. All the lines that are written to the stdout/console are saved to a json file. The log file is created at the same time the container is created and will grow until the container gets deleted. This can lead to disks getting full. To prevent this situations, log rotation can be configured.

daemon.json
{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m",
    "max-file": "3"
  }
}

Together with the default configuration, it looks like this.

daemon.json
{
  "builder": {
    "gc": {
      "defaultKeepStorage": "20GB",
      "enabled": true
    }
  },
  "experimental": false,
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m",
    "max-file": "3"
  }
}

WSL2

%UserProfile%\.wslconfig
[experimental]
autoMemoryReclaim=gradual
 
 
[wsl2]
memory=24GB
networkingMode=mirrored
dnsTunneling=true
firewall=true
autoProxy=true
[experimental]
autoMemoryReclaim=gradual

WSL2 Backend

WSL2 is the recommended backend

List Distributions

wsl -l -v
Example
PS C:\> wsl -l -v
  NAME                   STATE           VERSION
* docker-desktop-data    Running         2
  docker-desktop         Running         2
wsl -d docker-desktop
PS C:\> wsl -l -v
  NAME                   STATE           VERSION
* docker-desktop-data    Running         2
  docker-desktop         Running         2

PS C:\> wsl -d docker-desktop
DESKTOP-4D1F8L4:/#

Shrink VHDX

The virtual disks (VHDX) for the WSL2 VMs will grow to contain all the container data. If they get too big you have to do an offline shrink operation to get them back to a smaller size.

Make sure, the Docker Engine is stopped and close Docker Desktop for Windows.

Shutdown the WSL2 distributions.

wsl --shutdown

Shrink both disks with “Full” mode. Check this link for more information about the trimming modes.

Optimize-VHD -Path "C:\Users\xxx\AppData\Local\Docker\wsl\data\ext4.vhdx" -Mode Full
Optimize-VHD -Path "C:\Users\xxx\AppData\Local\Docker\wsl\main\ext4.vhdx" -Mode Full

If Optimize-VHD is done, just start Docker Desktop for Windows again.

Example.

PS C:\> Get-Item C:\Users\xxx\AppData\Local\Docker\wsl\data\ext4.vhdx

    Directory: C:\Users\xxx\AppData\Local\Docker\wsl\data

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----        04/06/2024     15:29   210780553216 ext4.vhdx

PS C:\> wsl --shutdown
PS C:\> Optimize-VHD C:\Users\xxx\AppData\Local\Docker\wsl\data\ext4.vhdx -Mode Full
PS C:\> Get-Item C:\Users\xxx\AppData\Local\Docker\wsl\data\ext4.vhdx

    Directory: C:\Users\xxx\AppData\Local\Docker\wsl\data

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----        04/06/2024     16:04    17706254336 ext4.vhdx