Skip to content

Instantly share code, notes, and snippets.

@nicolaskopp
Last active May 8, 2026 18:36
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"
@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.

@nshackr
Copy link
Copy Markdown

nshackr commented May 8, 2026

If fed up with all other tries, please give it a shot with the following. Run these commands one by one in an elevated command prompt after uninstalling the Docker Desktop application.

takeown /f "C:\ProgramData\Docker" /r /d y

icacls "C:\ProgramData\Docker" /grant Administrators:F /t /c

rd /s /q "\?\C:\ProgramData\Docker"

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