How do you mount the docker socket on Windows? How do you mount the docker socket on Windows? docker docker

How do you mount the docker socket on Windows?


If you cannot nor want use network sockets, then you can use named pipes.The syntax depends whether you run Linux or Windows containers and on the shell you use.

Linux containers

If you run Linux containers on a Windows machine, this seems to work using Powershell or bash:

docker run --rm -it -v "//var/run/docker.sock://var/run/docker.sock" image_with_docker docker version

Please note the extra / in front of /var/run/docker.sock, both for the source and destination volumes.

Windows containers

If you run Windows containers on a Windows machine, this seems to work using Powershell or bash:

docker run -v "//./pipe/docker_engine://./pipe/docker_engine" --rm -it image-with-docker docker version

Note that this works only in Powershell:

docker run -v "\\.\pipe\docker_engine:\\.\pipe\docker_engine" --rm -it image-with-docker docker version

Therefore, it's better to use the version with /.

Extra - docker-compose.yml

If you use a docker-compose.yaml file, this works with Windows containers.

version: '3.7'services:  docker:    image: image-with-docker    command:      - docker      - version    volumes:      - type: npipe        source: \\.\pipe\docker_engine        target: \\.\pipe\docker_engine

With Linux containers, you can use the shortened form:

  docker:    image: image-with-docker    command:      - docker      - version    volumes:      - //var/run/docker.sock://var/run/docker.sock

Extra - Kubernetes

If you are running Windows containers on a Windows node in Kubernetes, this seems to work:

apiVersion: v1kind: Podspec:  containers:    - name: docker      image: image-with-docker      command:        - powershell      args:        - Start-Sleep        - "999999"      volumeMounts:        - mountPath: \\.\pipe\docker_engine          name: dockersock  volumes:    - name: dockersock      hostPath:        path: \\.\pipe\docker_engine        type: null  nodeSelector:    kubernetes.io/os: windows

In this case, beside using the \, please note the type: null in the definition of the dockersock volume: if you don't set it, it will not work.

Notes

Everything was tested on docker 19.03 and on Kubernetes 1.18.

Client: Version:           19.03.3 API version:       1.40 Go version:        go1.12.10 Git commit:        2355349d- Built:             10/14/2019 16:41:26 OS/Arch:           windows/amd64 Experimental:      falseServer: Docker Engine - Community Engine:  Version:          19.03.8  API version:      1.40 (minimum version 1.24)  Go version:       go1.12.17  Git commit:       afacb8b  Built:            Wed Mar 11 01:37:20 2020  OS/Arch:          windows/amd64  Experimental:     false


If you encounter the following error on windows:

cannot create container for service portainer: Unrecognised volume spec: file '\.\pipe\docker_engine' cannot be mapped. Only directories can be mapped on this platformERROR: Encountered errors while bringing up the project.

Try adding an extra slash to it, resulting in following volumes section:

volumes:  - source: \\.\pipe\docker_engine\    target: \\.\pipe\docker_engine\    type: npipe

Tested with compose 3.7 and docker CE 19.03.12


Using short syntax with the type of the bind mount is not possible : npipe:////./pipe/docker_engine:/var/run/docker.sock:ro,delegated

You need to use the long syntax in your compose file :

volumes:  - type: npipe    source: ////./pipe/docker_engine    target: /var/run/docker.sock    consistency: delegated

You can find some documentation about the long syntax in the official documentation. This syntaxe is from v3.2

Also keep in mind what @lucas-ramage said about using windows container only when using npipe.