32

I'd like to know how to check if Docker is running on Windows by means of the command line (cmd or powershell).

Although, I've found several posts indicating the solution to this, they are for Linux environments:

How to check if docker is running or not

How to check if docker daemon is running?

I couldn't get the answer for Windows systems.

Bub Espinja
  • 4,029
  • 2
  • 29
  • 46

7 Answers7

27

Try running either of these commands on Powershell or cmd, if docker is installed, you should get a error free response:

docker --version

OR

docker-compose --version

OR

docker ps
KyleMit
  • 30,350
  • 66
  • 462
  • 664
ABusy_developerT
  • 486
  • 5
  • 12
  • 4
    I would recommend `docker ps` or `docker info` for cross-platform use. Unfortunately, `docker --version` completes successfully on other platforms like macOS even when Docker isn't running. – Noah Allen Apr 15 '21 at 21:47
  • "docker ps" (checks that docker is there AND running) is better than "docker --version" (only checks that docker is installed). The "docker ps" check works on Mac, Windows, and Ubuntu (probably works all Linux flavors but I use Ubuntu so that's what I'll report on) – Pierre Nov 09 '21 at 19:04
18

Afford two methods:

  1. docker version

    This method works both for cmd & powershell, but if for cmd, you need to use echo %errorlevel% to check the result.

    If docker daemon is running, it will be like next:

    PS C:\> docker version
    Client: Docker Engine - Community
    Version:           18.09.2
    API version:       1.39
    Go version:        go1.10.8
    Git commit:        6247962
    Built:             Sun Feb 10 04:12:31 2019
    OS/Arch:           windows/amd64
    Experimental:      false
    
    Server: Docker Engine - Community
     Engine:
      Version:          18.09.2
      API version:      1.39 (minimum version 1.12)
      Go version:       go1.10.6
      Git commit:       6247962
      Built:            Sun Feb 10 04:13:06 2019
      OS/Arch:          linux/amd64
      Experimental:     false
    PS C:\> echo $?
    True
    

    If docker daemon not running, it will be next:

    PS C:\> docker version
    Client: Docker Engine - Community
    Version:           18.09.2
    API version:       1.39
    Go version:        go1.10.8
    Git commit:        6247962
    Built:             Sun Feb 10 04:12:31 2019
    OS/Arch:           windows/amd64
    Experimental:      false
    Error response from daemon: An invalid argument was supplied.
    PS C:\> echo $?
    False
    
  2. Get-Process:

    This method just works for powershell.

    If docker daemon is running, it will be next:

    PS C:\> Get-Process 'com.docker.proxy'
    Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
    -------  ------    -----      -----     ------     --  -- -----------
        205      10    11416      18860       0.13  12620   2 com.docker.proxy
    PS C:\> echo $?
    True
    

    If docker daemon is not running, it will be next:

    PS C:\> Get-Process 'com.docker.proxy'
    Get-Process : Cannot find a process with the name "com.docker.proxy". Verify the process name and call the cmdlet
    again.
    At line:1 char:1
    + Get-Process 'com.docker.proxy'
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (com.docker.proxy:String) [Get-Process], ProcessCommandException
        + FullyQualifiedErrorId : NoProcessFoundForGivenName,Microsoft.PowerShell.Commands.GetProcessCommand
    
    PS C:\> echo $?
    False
    
atline
  • 28,355
  • 16
  • 77
  • 113
  • 2
    A Hint: `docker --version` will show show just the version. But `docker version` (without dashes) will show much more details. – KargWare Mar 25 '21 at 05:51
4

docker info

  • The operating-system independent way to check whether Docker is running is to ask Docker, using the docker info command. This option will work for both Windows and Linux distributions.
  • If Docker is running when you will get result as shown below, otherwise you will get an error message:
C:\Users\himanshu.agrawal>docker info
Client:
 Debug Mode: false
 Plugins:
  scan: Docker Scan (Docker Inc., v0.3.4)

Server:
 Containers: 1
  Running: 0
  Paused: 0
  Stopped: 1
 Images: 2
 Server Version: 19.03.13
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 8fba4e9a7d01810a393d5d25a3621dc101981175
 runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
 init version: fec3683
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 5.4.39-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 1.915GiB
 Name: docker-desktop
 ID: HHIB:HQRB:7VBA:LBUY:HKVJ:LFZ3:FSWZ:4ARP:74ZB:TIWO:WTMG:LHZH
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
 Product License: Community Engine

Get-Process 'com.docker.proxy'

  • This option can only be used with Windows Power Shell (just Power Shell, not even with CMD). If Docker is running you will get output as below, otherwise you will get an error message:
PS C:\Users\himanshu.agrawal> Get-Process 'com.docker.proxy'

Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
-------  ------    -----      -----     ------     --  -- -----------
    178      15    22984      25172       0.77  14224   1 com.docker.proxy

Other options - Linux specific

  • You can also use operating system utilities, such as sudo systemctl is-active docker or sudo status docker or sudo service docker status, or checking the service status using Windows utilities.
  • Finally, you can check in the process list for the "dockerd" process, using commands like ps or top.

Source 1

hagrawal7777
  • 14,103
  • 5
  • 40
  • 70
  • Get-Process will still work after it has been started but before it's ready. If you want to know when Docker is ready, not just started, docker info will only return a valid response when docker is started and also up and ready. – Steven Feb 27 '21 at 13:49
3

If using wsl2 on Windows, you can use:

wsl -l -v

Output will be something like the below:

  NAME                   STATE           VERSION
* Ubuntu                 Stopped         1
  docker-desktop         Running         2
  docker-desktop-data    Running         2
Venryx
  • 15,624
  • 10
  • 70
  • 96
1

I had the same issue while writing some scripts to work with Docker containers on Windows.

The answers given were not applicable for me because they just took too much time. I assumed that "is Docker running on Windows" also meant that the default VM was running. So instead the other answers I checked for the Docker default machine IP 192.168.99.100 which should normally be running when Docker is on. I then just pinged it:

ping -n <numberOfPings> -w <waitingTimeInMilliSeconds> 192.168.99.100

#Example:
ping -n 1 -w 1000 192.168.99.100

I found when Docker is running I normally get a response in less than 1ms which means the check is quite fast. This also means that it should be very robust to wait for even less than 1000ms if the Docker default machine is not running.

E_net4
  • 27,810
  • 13
  • 101
  • 139
TimFinnegan
  • 583
  • 5
  • 17
1

If you need a exact string only, you can use the go-lang formatting. Example: using docker info

 C:> docker info -f "{{.OSType}}"
 windows

 C:> docker info -f "{{.Architecture}}"
 x86_64

Example: using docker version

 C:> docker version -f "{{.Server.Os}}"
 windows

 C:> docker version -f "{{.Client.Os}}"
 windows

 C:> docker version -f "{{.Server.Arch}}"
 amd64

 C:> docker version -f "{{.Client.Arch}}"
 amd64
Yeo
  • 11,416
  • 6
  • 63
  • 90
0

Running docker ps when docker is not running will print to the error stream. You might want to capture both the error and input stream, and then test for an error.

The following will return true/false without writing anything to the console:

$dockerIsRunning = (docker ps 2>&1 | Out-String) -match "^(?!error)"

Further Reading

KyleMit
  • 30,350
  • 66
  • 462
  • 664