Bind to docker socket on Windows

2019-03-09 07:59发布

On *nix systems, it is possible to bind-mount the docker socket from the host machine to the VM by doing something like this:

docker run -v /var/run/docker.sock:/var/run/docker.sock ...

Is there an equivalent way to do this when running docker on a windows host?


I tried various combinations like:

docker run -v tcp://127.0.0.1:2376:/var/run/docker.sock ...

docker run -v "tcp://127.0.0.1:2376":/var/run/docker.sock ...

docker run -v localhost:2376:/var/run/docker.sock ...

none of these have worked.

标签: docker
4条回答
贼婆χ
2楼-- · 2019-03-09 08:28

Just to top it off on the answers provided earlier

When using docker-compose, one must set the COMPOSE_CONVERT_WINDOWS_PATHS=1 by either:

1) create a .env file at the same location as the project's docker-compose.yml file

2) in the CLI set COMPOSE_CONVERT_WINDOWS_PATHS=1

before running the docker-compose up command.

source

查看更多
地球回转人心会变
3楼-- · 2019-03-09 08:33

I never made it worked myself, but i know it works on windows container on docker for windows server 2016 using this technique: https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-socket-option

We actually have at the shop vsts-agents on windows containers that uses the host docker like that:

# listen using the default unix socket, and on 2 specific IP addresses on this host.    
$ sudo dockerd -H unix:///var/run/docker.sock -H tcp://192.168.59.106 -H tcp://10.10.10.2

# then you can execute remote docker commands (from container to host for example)
$ docker -H tcp://0.0.0.0:2375 ps
查看更多
仙女界的扛把子
4楼-- · 2019-03-09 08:43

For Docker for Windows following seems to be working: -v //var/run/docker.sock:/var/run/docker.sock

查看更多
The star\"
5楼-- · 2019-03-09 08:44

As the Docker documentation states:

If you are using Docker Machine on Mac or Windows, your Engine daemon has only limited access to your OS X or Windows filesystem. Docker Machine tries to auto-share your /Users (OS X) or C:\Users (Windows) directory. So, you can mount files or directories on OS X using:

docker run -v /Users/<path>:/<container path> ...

On Windows, mount directories using:

docker run -v /c/Users/<path>:/<container path> ...

All other paths come from your virtual machine’s filesystem, so if you want to make some other host folder available for sharing, you need to do additional work. In the case of VirtualBox you need to make the host folder available as a shared folder in VirtualBox. Then, you can mount it using the Docker -v flag.

With all that being said, you can still use the:

docker run -v /var/run/docker.sock:/var/run/docker.sock ...

The first /var/run/docker.sock refers to the same path in your boot2docker virtual machine.

For example, when I run my own Jenkins image using the following command in a Windows machine:

$ docker run -dP -v /var/run/docker.sock:/var/run/docker.sock alidehghanig/jenkins

I can still talk to the Docker Daemon in the host machine using the typical docker commands. For example, when I run docker ps in the Jenkins container, I can see running containers in the host machine:

CONTAINER ID   IMAGE  COMMAND   CREATED  STATUS  PORTS        NAMES
65311731f446   jen... "/bi.."   10...    Up 10.. 0.0.0.0:..  jenkins
查看更多
登录 后发表回答