I want to restart docker for windows
(now known as Docker Desktop) in powershell.
I would like to do it with one command in PowerShell.
May I implement it?
When using Restart-Service *docker*
:
I want to restart docker for windows
(now known as Docker Desktop) in powershell.
I would like to do it with one command in PowerShell.
May I implement it?
When using Restart-Service *docker*
:
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.
On windows, open Docker desktop and click on the debug icon then restart. You can also consider "reset to factory defaults"
You can user in powershell:
restart-service *docker*
Or int the Docker QuickStart Terminal:
docker-machine restart
Similar to Sebastian L's comment above, but slightly cleaner & faster if you know whether you are currently running Linux or Windows containers.
If running Linux Containers
Stop-Service *docker*
Start-Service *docker*
&$Env:ProgramFiles\Docker\Docker\DockerCli.exe -SwitchLinuxEngine
If running Windows Containers
Stop-Service *docker*
Start-Service *docker*
&$Env:ProgramFiles\Docker\Docker\DockerCli.exe -SwitchWindowsEngine
-SwitchDaemon toggles from one to the other (Linux to Windows or Windows to Linux) which is why you have to do it twice.