docker工人jenkins如何在另一个docker工人访问gitlab的git-repo

我在同一台服务器(我的笔记本电脑)上安装了gitlab-docker和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 

在myjenkinsdocker,使用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发布密钥的gitlab,这是行不通的。 帮帮我!!

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

它将直接使用另一个容器(这里是端口22)暴露的端口。
如果你的jenkins容器可以运行 – --link到gitlab容器,这将避免必须使用localhost或docker-machine ip和映射端口:你将直接使用gitlab-server:22