容器化Jenkins:在内部网络中建立与Docker云的连接 [英] Containerized Jenkins: establish connection to docker cloud in internal network

查看:214
本文介绍了容器化Jenkins:在内部网络中建立与Docker云的连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Mac连接到运行Jenkins的树莓派,以按需在Mac上启动docker build slaves。但是我无法在Jenkins的docker云配置中建立连接。



我的设置如下:




  • 树莓派位于192.168.2.111: Jenkins使用docker for mac在docker

  • mac mini在192.168.2.220上运行于docker

  • :这应通过Jenkins docker插件按需运行docker容器作为构建奴隶



从Jenkins到mac的SSH连接有效。 Mac代理已启动并正在运行。



现在,我想为詹金斯使用docker插件并尝试配置docker cloud。



由于Mac的docker不能直接在主机上运行(而是在hyperkit上),因此



所有教程我发现似乎詹金斯在将运行docker slave的同一主机上。我认为这就是为什么socat容器不够用的原因?



还有趣的是:
运行 curl 127.0.0.1在Mac上运行:2376 / version (显示预期信息),但是在树莓派上运行 curl 192.168.2.220:2376/version 不起作用(拒绝连接)。也许这可以帮助对网络有更多了解的人...

解决方案

上尉船长反击。



在Mac上启动socat时,只需使用网络IP而不是本地主机。

  docker run- d -v /var/run/docker.sock:/var/run/docker.sock -p 192.168.2.220:2376:2375 alpine / socat TCP-LISTEN:2375,叉unix-connect:/ var / run / docker。袜子


I am trying to connect a mac to a raspberry running Jenkins, to start docker build slaves on the mac on demand. But I can't establish the connection in Jenkins' docker cloud configuration.

My setup is as follows:

  • raspberry pi at 192.168.2.111: Jenkins running in docker
  • mac mini at 192.168.2.220 using docker for mac: this should run docker containers as build slaves on demand via Jenkins docker plugin

The SSH connection from Jenkins to mac works. The mac agent is up and running.

Now I want to use the docker plugin for Jenkins and trying to configure the docker cloud.

As docker for mac does not run directly on the host machine (but on hyperkit), they say I should run socat to expose the Unix socket like this:

docker run -d -v /var/run/docker.sock:/var/run/docker.sock -p 127.0.0.1:2376:2375 alpine/socat TCP-LISTEN:2375,fork unix-connect:/var/run/docker.sock

The container is running:

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                      NAMES
76a75c5249d7        alpine/socat        "socat tcp-listen:23…"   19 seconds ago      Up 17 seconds       127.0.0.1:2376->2375/tcp   compassionate_feynman

Then on the Raspberry pi where the Jenkins container is running, I have also added

DOCKER_OPTS="-H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock"

at the end of the file /etc/default/docker as described here.

Then in Jenkins cloud config "docker", I set "Docker Host URI" to tcp://127.0.0.1:2376, and the Docker Hostname (The mac mini) to 192.168.2.220. Testing this setting failed.

All the tutorials I find seem to have Jenkins on the same host where the docker slaves will be run. I assume this is why the socat container is not enough in my case?

What is also interesting: Running curl 127.0.0.1:2376/versionon the mac works (shows expected information), but running curl 192.168.2.220:2376/version from the raspberry does not work (Connection refused). Maybe this can help someone who knows more about networks...

解决方案

Captain Obvious strikes back.

Just use the network IP instead of localhost when starting socat on the mac.

docker run -d -v /var/run/docker.sock:/var/run/docker.sock -p 192.168.2.220:2376:2375 alpine/socat TCP-LISTEN:2375,fork unix-connect:/var/run/docker.sock

这篇关于容器化Jenkins:在内部网络中建立与Docker云的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆