且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

docker for windows如何从容器访问docker守护进程

更新时间:2023-09-15 13:38:46

我已经想到如何使用 socat 工具,它承担了docket.socket和代理TCP调用。



所以我已经启动了一个包含 socat 的容器,它装载了$ code> docker.sock ,因为它可以在VM内并公开2375端口:

  docker run -p 2375:2375 -v /var/run/docker.sock:/var/ run / docker.sock codenvy / socat -d -d TCP-L:2375,fork UNIX:/var/run/docker.sock 

现在,我可以通过 socat 容器访问docker守护程序API。


Im running docker for windows (hyper V) and I need to access docker daemon from the container via tcp. It is possible to connect to it from the host like: curl -v 127.0.0.1:2375/info but not possible to access it from a container using my host IP address. Maybe someone knows how to do that or at least how to ssh to that docker vm, for example it is possible to ssh in to it on mac by executing: screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty

I've figured how to do that using socat tool which takes docket.socket and proxy TCP calls to it.

So I've launched container with a socat which mount docker.sock since it is available inside of a VM and expose 2375 port:

docker run -p 2375:2375 -v /var/run/docker.sock:/var/run/docker.sock codenvy/socat -d -d TCP-L:2375,fork UNIX:/var/run/docker.sock

With that now, I'm able to access docker daemon API through socat container.