与Docker中的GitLab CI Runner和GitLab CE的连接被拒绝

时间:2018-12-06 18:00:46

标签: docker gitlab gitlab-ci gitlab-ci-runner gitlab-omnibus

尝试在Docker容器中同时运行GitLab CE和GitLab CI Runner时遇到问题。

这是我运行GitLab CE容器的方式:

docker run --detach \
  --name gitlab \
  --hostname gitlab.local \
  --publish 80:80 \
  --restart always \
  --env GITLAB_OMNIBUS_CONFIG="external_url 'http://gitlab.local/';" \
  --volume ~/volumes/gitlab/config:/etc/gitlab \
  --volume ~/volumes/gitlab/logs:/var/log/gitlab \
  --volume ~/volumes/gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce

然后我可以通过本地绑定的接口(即http://localhost)和容器IP(即http://gitlab.local)添加到主机上的GitLab,而不会在主机上出现任何问题172.17.0.2 gitlab gitlab.local在我的主机文件上。

当我尝试通过以下方式注册GitLab CI Runner容器时出现问题:

docker run --rm --tty --interactive \
    --name gitlab-runner-register \
    --add-host "gitlab.local:172.17.0.2" \
    --link=gitlab \
    --volume ~/volumes/gitlab-runner:/etc/gitlab-runner \
    gitlab/gitlab-runner \
        register \
            --non-interactive \
            --executor "docker" \
            --docker-image alpine:3 \
            --url "http://gitlab.local/" \
            --registration-token "XXXXXXXXXXXX" \
            --description "docker-runner" \
            --tag-list "docker" \
            --run-untagged \
            --locked="false"

我得到的错误是:

ERROR: Registering runner... failed                 runner=XXXXXX status=couldn't execute POST against http://gitlab.local/api/v4/runners: Post http://gitlab.local/api/v4/runners: dial tcp 172.17.0.2:80: getsockopt: connection refused
PANIC: Failed to register this runner. Perhaps you are having network problems

有帮助吗?预先感谢!

更新:我还尝试将BusyBox链接到gitlab容器。对其进行ping操作就像一种魅力,但wget对其进行操作会得到Connection refused

$ docker run --rm --link=gitlab busybox ping -c 1 gitlab
PING gitlab (172.17.0.2): 56 data bytes
64 bytes from 172.17.0.2: seq=0 ttl=64 time=0.124 ms

--- gitlab ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 0.124/0.124/0.124 ms

$ docker run --rm --link=gitlab busybox wget http://gitlab
Connecting to gitlab (172.17.0.2:80)
wget: can't connect to remote host (172.17.0.2): Connection refused

因此联网工作正常,可能“问题”与绑定关系更大。为了证明这一点,我尝试在gitlab容器中运行python http服务器,以便重试wget命令,并且...有效:

$ docker run --rm --link=gitlab busybox wget http://gitlab:8000
Connecting to gitlab:8000 (172.17.0.2:8000)
index.html           100% |********************************|  1065  0:00:00 ETA

0 个答案:

没有答案