O. Shekriladze
O. Shekriladze

Reputation: 1536

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

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?

Upvotes: 8

Views: 4563

Answers (2)

LF-DevJourney
LF-DevJourney

Reputation: 28554

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

Upvotes: 0

BMitch
BMitch

Reputation: 264831

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

Upvotes: 7

Related Questions