问题
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/version
on 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...
回答1:
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
来源:https://stackoverflow.com/questions/62291258/containerized-jenkins-establish-connection-to-docker-cloud-in-internal-network