Skip to content

Instantly share code, notes, and snippets.

@nicolaskopp
Last active April 28, 2026 15:05
Show Gist options
  • Select an option

  • Save nicolaskopp/de9fff4889d0ddf4c79da7ebc9e8b918 to your computer and use it in GitHub Desktop.

Select an option

Save nicolaskopp/de9fff4889d0ddf4c79da7ebc9e8b918 to your computer and use it in GitHub Desktop.
How to delete `C:\ProgramData\Docker` and fixing "Access denied" errors

How to delete C:\ProgramData\Docker and fix Access denied errors

I created this gist on May 25, 2021. It is still an issue as of February 16th, 2026. Welcome to the future of web development. Take this Gist to rest and calm down.

Dark Souls Campfire

Here is how to delete C:\ProgramData\Docker:

  1. Uninstall docker the normal way (yeah you may have already done that)
  2. Copy this (or download):
    # Leave swarm mode (this will automatically stop and remove services and overlay networks)
    docker swarm leave --force
    # Stop all running containers
    docker ps --quiet | ForEach-Object {docker stop $_}
    #just to be sure, sleep 5 seconds
    Start-Sleep -s 5
    #take ownership of docker files
    if (Test-Path "C:\ProgramData\Docker") { takeown.exe /F "C:\ProgramData\Docker" /R /A /D Y }
    if (Test-Path "C:\ProgramData\Docker") { icacls "C:\ProgramData\Docker\" /T /C /grant Administrators:F }
    #invoke cmd to delete docker files
    cmd /c rmdir /s /q "C:\ProgramData\Docker"
  1. save this as killDocker.ps1.
  2. go to start > powershell > run as administrator
  3. run .\killDocker.ps1

what this does:

  • kills all docker containers, if any
  • take ownership of all docker files within C:\ProgramData\Docker
  • remove C:\ProgramData\Docker by invoking cmd, because microsoft powershell is struggling to delete symlinks, of which docker has many

grab a coffee....

after 10 minutes or so it should be done. You're welcome.

# Leave swarm mode (this will automatically stop and remove services and overlay networks)
docker swarm leave --force
# Stop all running containers
docker ps --quiet | ForEach-Object {docker stop $_}
#just to be sure, sleep 5 seconds
Start-Sleep -s 5
#take ownership of docker files
if (Test-Path "C:\ProgramData\Docker") { takeown.exe /F "C:\ProgramData\Docker" /R /A /D Y }
if (Test-Path "C:\ProgramData\Docker") { icacls "C:\ProgramData\Docker\" /T /C /grant Administrators:F }
#invoke cmd to delete docker files
cmd /c rmdir /s /q "C:\ProgramData\Docker"
@Saffienn
Copy link
Copy Markdown

Thanks, docker got corrupted and wont start. Tried uninstall and install but that didn't work. Used the script to clean docker and install again. Im up and running with container again.

@venivediveci
Copy link
Copy Markdown

Thanks, worked nicely for me

@proBaxia
Copy link
Copy Markdown

proBaxia commented Dec 9, 2022

Thank you very much it works for me too

@jon-at-linkforge
Copy link
Copy Markdown

Thanks!

@yul14nrc
Copy link
Copy Markdown

yul14nrc commented Oct 5, 2023

Thanks!

@huysuper
Copy link
Copy Markdown

Thank!

@pierre-simonet
Copy link
Copy Markdown

Thanks !

@gsolic
Copy link
Copy Markdown

gsolic commented Apr 24, 2024

Thanks!

@VAllens
Copy link
Copy Markdown

VAllens commented Jul 23, 2024

Thanks!!! 💯 👍 🥇 :)

@dan937
Copy link
Copy Markdown

dan937 commented Oct 23, 2024

thank you. what a painful uninstall in 2024....

@SagePacheco
Copy link
Copy Markdown

A savior. Thank you.

@TylerHaynie
Copy link
Copy Markdown

Thank you! Docker stole 30GB of my hard drive and wouldn't give it back. Can't believe this is still an issue in 2025.

@Sash0check
Copy link
Copy Markdown

Latest docker version for now, problem still presist, thank you!

@TrippyZ
Copy link
Copy Markdown

TrippyZ commented Feb 15, 2026

Thanks. Absolutely beautiful.

@DuckTypeGames
Copy link
Copy Markdown

Umm... I think I ran into a problem. I followed the steps, saved the script on my desktop, navigated to the desktop in powershell and tried to run it. First it said scripts can't be run, so I had to run Set-ExecutionPolicy RemoteSigned first. Then I ran it again, and it first said something like "docker is not a recognized command", then it started setting administrator ownership. However, after a bit, it started setting permissions on files in my documents folder. I hit Ctrl+C to cancel it before it started deleting things. How did this happen?

@nicolaskopp
Copy link
Copy Markdown
Author

Interesting. I think icacls may have received a malformed path argument. Depending on how PowerShell and icacls parsed the script and especially quotation marks and backslashes, it could have fallen back to operating on the current directory or a parent path.

Since you said you navigated to your Desktop in PowerShell before running the script, and icacls with /T (traverse all subfolders) was running, it likely ended up operating on your user profile directory or Desktop, which would then traverse into your Documents folder.

What is your system language?

You could try

icacls "$env:USERPROFILE\Documents" /reset /T /C

This command is used in PowerShell to reset the NTFS permissions on your Documents folder to their default inheritance settings.

Then, you might want to try this slightly path-safer-"ish" version:

# Leave swarm mode (this will automatically stop and remove services and overlay networks)
docker swarm leave --force
# Stop all running containers
docker ps --quiet | ForEach-Object { docker stop $_ }
# Just to be sure, sleep 5 seconds
Start-Sleep -s 5

$dockerPath = "C:\ProgramData\Docker"

# Only proceed if the Docker folder actually exists
if (Test-Path $dockerPath) {
    # Take ownership of docker files
    takeown.exe /F $dockerPath /R /A /D Y
    # Grant Administrators full control — no trailing backslash inside quotes
    icacls $dockerPath /T /C /grant Administrators:F
    # Delete docker files
    cmd /c rmdir /s /q $dockerPath
}

@DuckTypeGames
Copy link
Copy Markdown

DuckTypeGames commented Apr 28, 2026

Thanks, it's still strange to me that it didn't just run on the contents of the Desktop, but I just set all my documents owner to me again.

Now I'm running the updated script, minus the cmd rmdir part because I still don't trust it.
It's been running for over half an hour, and it's "processing" a billion files. When I navigate to the folder in windowsfilter, I don't see Documents and Settings, nor do I understand why docker apparently needed all the users and files in my container?
image

Moreover, as it goes, it's eating up disk space on C: like gigs worth... what's going on?

@nicolaskopp
Copy link
Copy Markdown
Author

I have no idea. Sounds like the script is just not working for you for whatever reason. Sorry for that. Maybe you can debug it with a Claude Code Session or something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment