Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create uninstall-docker-ce.ps1 #435

Closed
wants to merge 1 commit into from
Closed

Conversation

brasmith-ms
Copy link
Contributor

Uninstall script for docker ce

Uninstall script for docker ce
@ntrappe-msft
Copy link
Contributor

ntrappe-msft commented Oct 24, 2023

I've got a few suggestions on how we could improve the script to be a bit more error-friendly. Please let me know if these are unnecessary since PowerShell scripting is still new to me.

  1. I agree that we should have a confirmation of whether a user wants to proceed because they may have containers running. I think we could go a step farther and tell them if they do have containers running (or images). We could do something like:
# Docker was installed so check if the service is running
if ((Get-Service -Name $global:DockerServiceName).Status -eq "Running")
{
    # Check that no containers are running or warn user
    if ($global:GetContainers -match "Up")
    {
        Write-Output "There are running containers."
        $response = Read-Host "Do you want to proceed? (Type 'yes' to continue or 'no' to exit)"

        # Stop uninstall if they do not want to proceed
        if ($response -ieq "no" -or $response -ieq "n")
        {
            Write-Output "Aborting uninstall."
            return
        }

        # Continue with uninstall by stopping the service
        Stop-Service -Name $global:DockerServiceName
    }
}
  1. I tend to check if a service is installed or running before trying an uninstall. (Mainly because someone could have attempted part of the uninstall but abandoned it partway through).
# Check if Docker was installed before proceeding
if ((Get-Service -Name $global:DockerServiceName -ErrorAction SilentlyContinue) -eq $null)
{
    Write-Output "Docker was not installed. Aborting."
    return
}
# Docker service is not running so unregister dockerd next
if ((Get-Service -Name $global:DockerdServiceName -ErrorAction SilentlyContinue) -ne $null)
{
    # Remove dockerd
    & dockerd --unregister-service
}
  1. And I like doing a check at the very end of our expected behavior to confirm from our side that it worked.
# Check that we successfully removed docker
if ((Get-Service -Name $global:DockerServiceName -ErrorAction SilentlyContinue) -eq $null)
{
    Write-Output "Docker-CE was uninstalled."
}
else
{
    Write-Output "An error occured and failed to uninstall Docker-CE."
}

Copy link
Contributor

This issue has been open for 30 days with no updates.
no assignees, please provide an update or close this issue.

3 similar comments
Copy link
Contributor

This issue has been open for 30 days with no updates.
no assignees, please provide an update or close this issue.

Copy link
Contributor

This issue has been open for 30 days with no updates.
no assignees, please provide an update or close this issue.

Copy link
Contributor

This issue has been open for 30 days with no updates.
no assignees, please provide an update or close this issue.

@ntrappe-msft ntrappe-msft deleted the brasmith-ms-patch-1 branch June 28, 2024 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants