如何检查 Docker 是否在 Windows 上运行?

Bub*_*nja 14 windows powershell cmd docker

我想知道如何通过命令行(cmd 或 powershell)检查 Docker 是否在 Windows 上运行。

虽然,我发现了几篇文章指出了解决方案,但它们适用于 Linux 环境:

如何检查docker是否正在运行

如何检查docker守护进程是否正在运行?

我无法得到 Windows 系统的答案。

小智 13

尝试在 Powershell 或 cmd 上运行这些命令中的任何一个,如果安装了 docker,您应该得到无错误响应:

docker --version

docker-compose --version

docker ps

  • 我建议使用“docker ps”或“docker info”进行跨平台使用。不幸的是,即使 Docker 未运行,“docker --version”也能在 macOS 等其他平台上成功完成。 (6认同)

atl*_*ine 11

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
    
    Run Code Online (Sandbox Code Playgroud)

    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
    
    Run Code Online (Sandbox Code Playgroud)
  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
    
    Run Code Online (Sandbox Code Playgroud)

    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
    
    Run Code Online (Sandbox Code Playgroud)

  • 提示:“docker --version”将仅显示版本。但“docker version”(不带破折号)将显示更多详细信息。 (3认同)

hag*_*wal 5

码头工人信息

  • 检查 Docker 是否正在运行的独立于操作系统的方法是使用 docker info 命令询问 Docker。此选项适用于 Windows 和 Linux 发行版。
  • 如果 Docker 正在运行,那么你会得到如下所示的结果,否则你会得到一条错误消息:
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
Run Code Online (Sandbox Code Playgroud)

获取进程'com.docker.proxy'

  • 此选项只能与 Windows Power Shell 一起使用(仅 Power Shell,甚至不能与 CMD 一起使用)。如果 Docker 正在运行,您将得到如下输出,否则您将收到错误消息:
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
Run Code Online (Sandbox Code Playgroud)

其他选项 - Linux 特定

  • 您还可以使用操作系统实用程序,例如sudo systemctl is-active dockersudo status dockersudo service docker status,或使用 Windows 实用程序检查服务状态。
  • ps最后,您可以使用或 等命令检查“dockerd”进程的进程列表top

来源1


归档时间:

查看次数:

26098 次

最近记录:

4 年,4 月 前