If you’re using Sitecore Docker containers on Windows, you’ve probably noticed your disk space mysteriously shrinking over time. I recently encountered this issue myself and was surprised to discover the culprit: orphaned Docker layers – leftover chunks of data that no longer belong to any container or image.
My Setup
This happened while I was working with Sitecore XP 10.2 in a Dockerized environment. After several rounds of running’ docker-compose up’ and rebuilding custom images, Docker started hoarding storage, and the usual’ docker system prune’ didn’t fully resolve the issue.
That’s when I stumbled upon a great blog post by Vikrant Punwatkar: Regain disk space occupied by Docker
Inspired by his approach, I automated the cleanup process with PowerShell, and it worked like a charm. Let me walk you through it.
So, What Are Orphan Docker Layers?
Docker uses layers to build and manage images. Over time, when images are rebuilt or containers removed, some layers are left behind. These “orphan” layers hang around in your system, specifically under:
C:ProgramDataDockerwindowsfilter
They’re not in use, but they still consume gigabytes of space. If you’re working with large containers, such as Sitecore’s, these can add up quickly.
Step-by-Step Cleanup with PowerShell
I broke the cleanup process into two simple scripts:
- Identify and optionally rename orphan layers
- Delete the renamed layers after fixing permissions
Script 1: Find-OrphanDockerLayers.ps1
This script compares the layers used by active images and containers against what’s actually on your disk. Anything extra is flagged as an orphan. You can choose to rename those orphan folders (we add -removing at the end) for safe deletion.
What it does
- Scans the image and container layers
- Compared with the actual Docker filesystem folders
- Identifies unused (orphan) layers
- Calculates their size
- Renames them safely (optional)
A. Download PowerShell script and execute (as Administrator) with the parameter -RenameOrphanLayers
B. To Run:
.Find-OrphanDockerLayers.ps1 -RenameOrphanLayers
C. Sample Output:
WARNING: YOUR-PC - Found orphan layer: C:ProgramDataDockerwindowsfilterabc123 with size: 500 MB ... YOUR-PC - Layers on disk: 130 YOUR-PC - Image layers: 90 YOUR-PC - Container layers: 15 WARNING: YOUR-PC - Found 25 orphan layers with total size 4.8 GB
This provides a clear picture of the space you can recover.
Delete After Stopping Docker
Stop Docker completely first using the below PowerShell command, or you can manually stop the Docker services:
Stop-Service docker
Script 2: Delete-OrphanDockerLayers.ps1
Once you’ve renamed the orphan layers, this second script deletes them safely. It first fixes folder permissions using takeown and icacls, which are crucial for system directories like these.
A. Download the PowerShell script and execute (as Administrator)
B. To Run:
.Delete-OrphanDockerLayers.ps1
C. Sample Output:
Fixing permissions and deleting: C:ProgramDataDockerwindowsfilterabc123-removing ...
Simple and effective — no manual folder browsing or permission headaches.
End Result: A Cleaner, Lighter Docker
After running these scripts, I was able to recover multiple gigabytes of storage, and you’ll definitely benefit from this cleanup. If you’re frequently working with:
- Sitecore custom Docker images
- Containerized development setups
- Large volume-mounted projects
Pro Tips
- Run PowerShell as Administrator – especially for the delete script.
- Don’t delete folders manually – rename first to ensure safety.
- Use -RenameOrphanLayers only when you’re ready to clean up. Otherwise, run the script without it for a dry run.
- Consider scheduling this monthly if you’re actively building and tearing down containers.
Credit Where It’s Due
Huge thanks to Vikrant Punwatkar for the original idea and guidance. His blog post was the foundation for this automated approach.
Check out his post here: Regain disk space occupied by Docker
Final Thoughts
If your Docker setup is bloated and space is mysteriously disappearing, try this approach. It’s quick, safe, and makes a noticeable difference – especially on Windows, where Docker’s cleanup isn’t always as aggressive as we’d like.
Have you tried it? Got a different solution? Feel free to share your thoughts or suggestions for improvement.
Source: Read MoreÂ