microsoft / Windows-Containers

Welcome to our Windows Containers GitHub community! Ask questions, report bugs, and suggest features -- let's work together.
MIT License
393 stars 60 forks source link

On windows server, how do i uninstall? #433

Closed beckerben closed 10 months ago

beckerben commented 10 months ago

I didn't see any mention in the documentation if we installed using the install-docker-ce.ps1 on windows server how to actually perform an uninstallation? We wanted to move the installation from C:\ to D:\ an wasn't sure how to properly do the uninstall.

ntrappe-msft commented 10 months ago

Hi! Great question. @brasmith-ms might know more about this than I but I can take a stab at it.

  1. Make sure you kill any containers that are running or push any images you want to save to Docker Hub.
    # Check if any containers are still running
    docker ps
  2. Stop the Docker service so you can remove it. Run the following an Administrator PowerShell window:
    Stop-Service -Name docker
  3. Unregister dockerd also in that PowerShell window:
    & dockerd --unregister-service
  4. Remove docker from your ProgramData folder. (This path might be different for you depending on your configuration but it's under C:/ for me).
    Remove-Item -Path C:\ProgramData\docker -Recurse
  5. Check that the Docker service no longer exists:
    $service = Get-Service -Name "docker" -ErrorAction SilentlyContinue
    $service -eq $null
    # if it prints out True then docker is not installed (yay)
    # if it prints out False then a previous command failed
beckerben commented 10 months ago

@ntrappe-msft looks easy enough, thanks.

It probably makes sense to get a section added to the formal docs for reference as well.

ntrappe-msft commented 10 months ago

Totally agree, we'll write up something. Just re-open this if anything doesn't work.

SanielDous commented 10 months ago

I previously installed Containerd together with nerdctl. I want to switch to Moby/Docker CE and thereby uninstall containerd/nerdctl. I ran the commands from above and switched docker with containerd. But in step 4 when trying to remove the program data I get a lot of access violations (although I ran it in an elevated PS).

For example:

Remove-Item : Cannot remove item C:\ProgramData\containerd\root\io.containerd.snapshotter.v1.windows\snapshots\9\Files\Windows\WaaS: Access to the path 'WaaS' is denied.
beckerben commented 10 months ago

We just got around to trying this process that @ntrappe-msft mentioned and ran into permission errors doing the delete from an elevated shell. We found that in order to delete the "docker" folder we had to take ownership of it and then were able to perform the delete.

beckerben commented 10 months ago

I spoke too soon, the command looked like it was working but it ended up having issues removing the "C:\ProgramData\docker\windowsfilter". We ended up having to use this: https://github.com/moby/docker-ci-zap

ntrappe-msft commented 10 months ago

Hmm I'll look into what's happening. Thanks for the heads up.

ntrappe-msft commented 10 months ago

Ah yep it's probably not a good idea to use the docker-ci-zap tool unless you never want to install docker again. It doesn't let you automatically delete the docker/windowsfilter folder because it's actually the storage driver Docker uses to save images and container metadata. I'll work on an uninstall script that can safely remove the driver and everything else.

beckerben commented 10 months ago

I see, we had no problems using the tool and then re-installing. We were hoping to install to a different drive altogether but not sure that is possible from what we have seen so we ended up re-installing everything via the script and moved our data directory to another drive.

CebolaBros64 commented 3 months ago

Hi! Great question. @brasmith-ms might know more about this than I but I can take a stab at it.

  1. Make sure you kill any containers that are running or push any images you want to save to Docker Hub.
# Check if any containers are still running
docker ps
  1. Stop the Docker service so you can remove it. Run the following an Administrator PowerShell window:
Stop-Service -Name docker
  1. Unregister dockerd also in that PowerShell window:
& dockerd --unregister-service
  1. Remove docker from your ProgramData folder. (This path might be different for you depending on your configuration but it's under C:/ for me).
Remove-Item -Path C:\ProgramData\docker -Recurse
  1. Check that the Docker service no longer exists:
$service = Get-Service -Name "docker" -ErrorAction SilentlyContinue
$service -eq $null
# if it prints out True then docker is not installed (yay)
# if it prints out False then a previous command failed

Thanks, these instructions worked just fine for uninstalling the Docker server in our case. But, how would one go about uninstalling the the Docker client after this? We're planning on installing Docker to a different machine instead, and we have no use on having the client still sitting there

ntrappe-msft commented 3 months ago

@CebolaBros64 Are you trying to remove the Docker CLI? Usually the Docker Client consists of that.

CebolaBros64 commented 3 months ago

@ntrappe-msft Yes, that's correct

ntrappe-msft commented 3 months ago

Did you try removing Docker Desktop? That's usually what adds/removes the Docker CLI.

CebolaBros64 commented 3 months ago

Docker Desktop isn't installed, as the machine is running Windows Server 2019 and isn't compatible. I was under the impression the install-docker-ce.ps1 script was what added the CLI, is that not the case?

ntrappe-msft commented 3 months ago

Hi, you're right, the install-docker-ce.ps1 script does install it. I just wanted to make sure that's what you were working with. We're going to release an official uninstall script soon but here are some steps you can take in the meantime:

  1. Check which Docker files you have remaining.
    where.exe docker
  2. You should see these two locations:
    C:\Program Files\Docker\Docker\resources\bin\docker
    C:\Program Files\Docker\Docker\resources\bin\docker.exe
  3. Remove those files and/or any others the command noted.
    Remove-Item -Path "C:\Program Files\Docker\Docker\resources\bin\docker" -ErrorAction SilentlyContinue
    Remove-Item -Path "C:\Program Files\Docker\Docker\resources\bin\docker.exe" -ErrorAction SilentlyContinue
  4. Check that the Docker CLI is gone. You should get an error like "The term 'docker' is not recognized".
    docker
CebolaBros64 commented 3 months ago

Thank you, that did the job :)