![](/img/trans.png)
[英]How to do a health-check to Spring Boot app running inside Windows Docker Windows Container with Ansible?
[英]How to check if Docker is running on Windows?
我想知道如何通过命令行(cmd 或 powershell)检查 Docker 是否在 Windows 上运行。
虽然,我发现了几篇表明解决方案的帖子,但它们适用于 Linux 环境:
如何检查 docker daemon 是否正在运行?<\/a>
我无法得到 Windows 系统的答案。
尝试在 Powershell 或 cmd 上运行这些命令中的任何一个,如果安装了 docker,您应该得到无错误响应:
docker --version
或者docker-compose --version
或者docker ps
提供两种方法:
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
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
等命令检查“dockerd”进程的进程列表。我在编写一些脚本以在 Windows 上使用 Docker 容器时遇到了同样的问题。
给出的答案不适用于我,因为它们花费了太多时间。 我认为“Docker 在 Windows 上运行”也意味着default
VM 正在运行。 因此,我检查了 Docker default
机器 IP 192.168.99.100
的其他答案,该 IP 应该在 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 毫秒应该是非常健壮的。
如果在 Windows 上使用 wsl2,您可以使用:
wsl -l -v
输出将类似于以下内容:
NAME STATE VERSION
* Ubuntu Stopped 1
docker-desktop Running 2
docker-desktop-data Running 2
您可以通过编写以下命令使用 Powershell、cmd 或 cmder 检查 Windows
码头工人--版本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.