How to restart docker for windows process in powershell?

pwxcoo picture pwxcoo · Aug 9, 2018 · Viewed 12k times · Source

I want to restart docker for windows in powershell.

just like I can do it with one command in powershell.

enter image description here

May I implement it?

When using Restart-Service *docker*:

enter image description here

Answer

eddex picture eddex · Oct 3, 2018

Kill and restart the docker process:

$processes = Get-Process "*docker desktop*"
if ($processes.Count -gt 0)
{
    $processes[0].Kill()
    $processes[0].WaitForExit()
}
Start-Process "C:\Program Files\Docker\Docker\Docker Desktop.exe"

In the if clause I check if any running docker process has been found. There should never be more than 1 instance of "Docker Desktop" running so you can then kill the first one in the list.

To restart you need to know the full path of the "Docker Desktop.exe" file on your computer.