docker 中的 jenkins 如何访问另一个 docker 中 gitlab 的 git-repo

how jenkins in a docker access git-repo of gitlab in another docker

我在同一台服务器(我的笔记本电脑)上安装了两个 gitlab-docker and jenkins-docker

docker run --name gitlab-postgresql -d \
--env 'DB_NAME=gitlabhq_production' \
--env 'DB_USER=gitlab' --env 'DB_PASS=password' \
--volume /srv/docker/gitlab/postgresql:/var/lib/postgresql \
quay.io/sameersbn/postgresql:9.4-5

docker run --name gitlab-redis -d \
--volume /srv/docker/gitlab/redis:/var/lib/redis \
quay.io/sameersbn/redis:latest

docker run --name gitlab -d \
--link gitlab-postgresql:postgresql --link gitlab-redis:redisio \
--publish 10022:22 --publish 80:80 \
--env 'GITLAB_PORT=10080' --env 'GITLAB_SSH_PORT=10022' \
--env 'GITLAB_SECRETS_DB_KEY_BASE=long-and-random-alpha-numeric-string' \
--volume /srv/docker/gitlab/gitlab:/home/git/data \
quay.io/sameersbn/gitlab:8.0.5-1

docker run --name myjenkins -p 8080:8080 -v /var/jenkins_home jenkins

在 myjenkins docker 中,使用 bash 到 运行

git ls-remote -h ssh://git@localhost:10022/rhtj/yirongtong.git HEAD 

git ls-remote -h ssh://git@10.0.0.131:10022/rhtj/yirongtong.git HEAD 

其中说:

ssh:connect to host localhost port 10022: Connection refused
fatal: Could not read from remote repository.

并且我已经将 ssh pub-key 添加到 gitlab,但无法正常工作。 求助!!

当一个容器(使用默认网桥驱动程序)需要联系另一个容器时,它不需要使用映射(到主机)端口。

它将直接使用其他容器暴露的端口(这里是端口 22)。
如果你的 jenkins 容器可以 运行 和 --link 到 gitlab 容器,那将避免使用本地主机或 docker-机器 ip 和映射端口:你将直接使用 gitlab-server:22.