====== 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. * It only works within an interactive user session * There are memory usage problems: [[https://github.com/docker/for-win/issues/12944|GitHub: docker/for-win Issue #12944]] ===== Configuration ===== ==== Docker Daemon ==== %UserProfile%\.docker\daemon.json Default configuration as of Docker Desktop for Windows version 4.30.0 (2024-06-06). { "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. { "log-driver": "json-file", "log-opts": { "max-size": "100m", "max-file": "3" } } Together with the default configuration, it looks like this. { "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 * "%LOCALAPPDATA%\Docker\wsl\data\ext4.vhdx" ("C:\Users\xxx\Docker\wsl\data\ext4.vhdx") * "%LOCALAPPDATA%\Docker\wsl\main\ext4.vhdx" ("C:\Users\xxx\Docker\wsl\main\ext4.vhdx") ==== List Distributions ==== wsl -l -v 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 [[https://learn.microsoft.com/en-us/powershell/module/hyper-v/optimize-vhd?view=windowsserver2022-ps|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 ===== Links ===== * [[https://www.docker.com/blog/new-docker-desktop-wsl2-backend/|Introducing the Docker Desktop WSL 2 Backend]]