Docker Community Forums

Share and learn in the Docker community.

Feature detect Docker for Windows?


(Per Rovegård) #1

How do you detect that Docker for Windows is running, as opposed to boot2docker or Docker Machine?

On Mac, I test the presence of a /var/run/docker.sock socket. But on Windows?

My ideas so far are:

  • grep the output of docker info and test that the name is “moby”
  • test connectivity to the Docker Engine API on localhost:2375

But I’m unsure if these could give false positives, especially the name test.

Ideas?


(Michael Friis) #2

What about checking for the named pipe or sending a request there? Details here: https://docs.docker.com/docker-for-windows/faqs/#/how-do-i-connect-to-the-remote-docker-engine-api


(Per Rovegård) #3

Connecting to the named pipe doesn’t work for me. This PowerShell snippet:

$pipe = new-object System.IO.Pipes.NamedPipeClientStream("\\.\pipe\docker_engine")
$pipe.Connect()

…just hangs. Using npipe:////./pipe/docker_engine as the FAQ suggests gives me an error about incorrect format.

Process Explorer doesn’t find any named pipe with “docker_engine” in the name.

However, connecting to http://localhost:2375 works. Maybe that’s the best approach after all.


(Michael Friis) #4

The pipe is there when Docker for Windows is running:

docker -H npipe:////./pipe/docker_engine version
Client:
 Version:      1.12.1
 API version:  1.24
 Go version:   go1.6.3
 Git commit:   23cf638
 Built:        Thu Aug 18 17:32:24 2016
 OS/Arch:      windows/amd64
 Experimental: true

Server:
 Version:      1.12.1
 API version:  1.24
 Go version:   go1.6.3
 Git commit:   23cf638
 Built:        Thu Aug 18 17:32:24 2016
 OS/Arch:      linux/amd64
 Experimental: true
[System.IO.Directory]::GetFiles("\\.\\pipe\\") | Select-String -pattern "docker"

\\.\\pipe\\PSHost.131176286632409278.26752.DefaultAppDomain.com.docker.service
\\.\\pipe\\dockerBackend
\\.\\pipe\\dockerLogs
\\.\\pipe\\PSHost.131178195006249300.8044.DefaultAppDomain.Docker for Windows
\\.\\pipe\\dockerDataBase
\\.\\pipe\\dockerMobyLinuxVM-com1
\\.\\pipe\\docker_engine

(Per Rovegård) #5

The first command works!

(The second doesn’t, I get “Second path fragment must not be a drive or UNC name” - but it doesn’t matter.)

Thanks!