我想知道如何通过命令行(cmd或powershell)检查Docker是否在Windows上运行。
尽管,我发现了几篇文章指出了解决方案,但是对于Linux:
How to check if docker is running or not
How to check if docker daemon is running?
我找不到Windows系统的答案。
答案 0 :(得分:3)
尝试在Powershell或cmd上运行以下命令之一,如果已安装docker,则应获得无错误的响应:
docker --version
或
docker-compose --version
或
docker ps
答案 1 :(得分:2)
负担两种方法:
docker version
此方法同时适用于cmd
和powershell
,但是如果适用于cmd
,则需要使用echo %errorlevel%
来检查结果。
如果docker daemon
正在运行,则类似于下一个:
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
如果docker daemon
未运行,将是下一个:
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
Get-Process
:
此方法仅适用于powershell
。
如果docker daemon
正在运行,它将是下一个:
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
如果docker daemon
不在运行,它将是下一个:
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
答案 2 :(得分:1)
在编写一些脚本以在Windows上使用Docker容器时,我遇到了同样的问题。
给出的答案不适用于我,因为它们花费了太多时间。我认为“正在Windows上运行Docker” 也意味着default
VM正在运行。因此,我用其他答案来检查Docker default
机器IP 192.168.99.100
,该机器通常应在Docker打开时运行。然后,我便对其进行ping操作:
ping -n <numberOfPings> -w <waitingTimeInMilliSeconds> 192.168.99.100
#Example:
ping -n 1 -w 1000 192.168.99.100
我发现当Docker运行时,我通常会在不到1毫秒的时间内得到响应,这意味着检查非常快。这也意味着,如果Docker default
计算机未运行,则等待时间甚至少于1000毫秒应该非常强大。
答案 3 :(得分:1)
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
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
sudo systemctl is-active docker
或 sudo status docker
或 sudo service docker status
,或使用 Windows 实用程序检查服务状态。ps
或 top
等命令。答案 4 :(得分:1)
如果在 Windows 上使用 wsl2,您可以使用:
wsl -l -v
输出将类似于以下内容:
NAME STATE VERSION
* Ubuntu Stopped 1
docker-desktop Running 2
docker-desktop-data Running 2