Free up space used by Docker
Docker can consume a significant amount of disk space over time. Here are some tips to reclaim disk space used by Docker:
-
Remove unused containers:
powershell docker container prune -
Remove unused images:
powershell docker image prune -
Remove unused volumes:
powershell docker volume prune -
Remove unused networks:
powershell docker network prune -
Remove all unused data:
powershell docker system prune
By regularly cleaning up unused Docker resources, you can free up valuable disk space.
Once the above is done, you can optimise the space used by the Docker VHD by running the following commands in an elevated PowerShell prompt:
# Stop the Docker service
docker desktop stop
# Optimize the Docker VHD
Optimize-VHD -Path C:\Users\<YourName>\AppData\Local\Docker\wsl\disk\docker_data.vhdx -Mode full
# Start the Docker service
docker desktop start
Obviously, replace <YourName> with your actual Windows username.