问题描述
我是OSX的Docker管理员,但无法使Docker远程API正常工作.
I'm runner Docker for OSX, and having trouble getting the Docker remote API to work.
我的情况是这样:
- 在OSX上本地运行的Docker守护程序( https://www.docker.com/products/docker#/mac ,而不是boot2docker变体)
- Jenkins作为docker映像运行
- Docker daemon running natively on OSX (https://www.docker.com/products/docker#/mac, so not the boot2docker variant)
- Jenkins running as docker image
否,我不想使用Jenkins docker-build-step插件来构建docker映像,但是我希望它使用主机上的docker守护程序,因此在Jenkins设置中,DOCKER_URL应该类似于:2375. (这样做的原因是,如果我已经在主机上安装了docker,则我不想将其安装在jenkins容器上).
No I want to use the Jenkins docker-build-step plugin to build a docker image, but I want it to use the docker daemon on the host machine, so in Jenkins settings, DOCKER_URL should be something like :2375. (Reason for this is I don't want to install docker on the jenkins container if I already have it on my host machine).
有没有办法解决此问题,或者Mac版Docker目前不支持此操作?我尝试摆弄导出DOCKER_OPTS或DOCKER_HOST选项,但仍然在调用 http://localhost:2375/images/时仍然拒绝连接json .
Is there a way to to this or is de Docker for Mac currently not supporting this? I tried fiddling with export DOCKER_OPTS or DOCKER_HOST options but still get a Connection refused on calling http://localhost:2375/images/json for example.
基本上,问题更多是关于启用Docker for OSX远程api,用例是从Jenkins docker容器调用它.
Basicly the question is more about enabling the Docker for OSX remote api, with use case calling it from a Jenkins docker container.
推荐答案
您可以考虑使用socat.它解决了我的问题,看起来很相似.
You could consider using socat. It solved my problem, which seem to be similar.
socat TCP-LISTEN:2375,reuseaddr,fork UNIX-CONNECT:/var/run/docker.sock &
这使您可以使用tcp://[host IP address]:2375
在macOS上,可以这样安装socat:
On macOS socat can be installed like this:
brew install socat
有关此主题的详细讨论,请参见此处:插件:Docker无法通过unix连接://在Mac OS X上
See here for a long discussion on this topic: Plugin: Docker fails to connect via unix:// on Mac OS X
这篇关于在Mac上的Docker上访问Docker守护进程远程API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!