23

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.

enter image description here

May I implement it?

When using Restart-Service *docker*:

enter image description here

pwxcoo
  • 2,903
  • 2
  • 15
  • 21

4 Answers4

28

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.

eddex
  • 1,622
  • 1
  • 15
  • 37
13

On windows, open Docker desktop and click on the debug icon then restart. You can also consider "reset to factory defaults"

enter image description here

Piaget Hadzizi
  • 702
  • 8
  • 15
10

You can user in powershell:

restart-service *docker*

Or int the Docker QuickStart Terminal:

docker-machine restart
mlameiras
  • 400
  • 1
  • 11
  • cannot work... just kill the docker daemon, but docker cannot restart. – pwxcoo Aug 09 '18 at 11:01
  • 2
    restart-service *docker* does in fact stop and start com.docker.service, which is what we're after. But it's not successful; after you do it, you have a broken docker (can't connect, can't do anything) – rfay Jan 30 '19 at 23:32
  • 2
    While this does restart the docker desktop service (com.docker.service), it doesn't result in a working docker. I'm pretty sure you have to recreate the Hyper-V instance to do that? – rfay Feb 01 '19 at 14:17
  • "& $Env:ProgramFiles\Docker\Docker\DockerCli.exe -SwitchDaemon" resolves the problem, but you might need to run it twice. – Sebastian L Dec 12 '19 at 11:58
4

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.