How /var/run/docker.sock works for windows Docker?
Asked Answered
S

2

8

I have Docker installed on my Windows OS. There is my volumes filed of docker-compose.yml:

volumes:
  - "/var/run/docker.sock:/var/run/docker.sock"

I just can't figure out how /var/run/docker.sock::/var/run/docker.sock path works for windows as I have no /var/run/ on my windows files where I can find docker.sock. So how this volume binding works at all?

Sorkin answered 9/5, 2019 at 18:3 Comment(2)
Is this for a Linux image on Windows or native Windows image? docker system info --format '{{.OSType}}'Sawhorse
Linux image on WindowsSorkin
S
7

The /var/run/docker.sock file on Docker for Mac and Windows for Linux images is inside the VM that Docker uses to run Linux containers. Those volume mounts happen from inside of that VM to the containers running in the VM. This is also why you can get an empty directory if you try to run a volume mount to a directory that you have not shared with the embedded VM.

You cannot see this file directly from the Windows environment (at least not that I'm aware of), though you can mount it into a container and see it that way.

For more details on how this VM is created, you can see the LinuxKit project: https://github.com/linuxkit/linuxkit

Sawhorse answered 9/5, 2019 at 18:55 Comment(0)
B
0

On mac/linux, /var/run/docker.sock is a unix sock which is used between process communication.

But windows doesn't has the unix sock, so it use named pipe instead.

When windows docker runs, you can use docker context inspect to see the npipe:////./pipe/docker_engine.

docker context inspect
[
    {
        "Name": "default",
        "Metadata": {},
        "Endpoints": {
            "docker": {
                "Host": "npipe:////./pipe/docker_engine",
                "SkipTLSVerify": false
            }
        },
        "TLSMaterial": {},
        "Storage": {
            "MetadataPath": "\u003cIN MEMORY\u003e",
            "TLSPath": "\u003cIN MEMORY\u003e"
        }
    }
]

And on windows if you want to bind /var/run/docker.sock, you can use it like this: which is often used by some CI/CD jobs

    volumes:
      - //var/run/docker.sock:/var/run/docker.sock
Basilbasilar answered 19/9, 2024 at 6:34 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.