sameersbn / docker-gitlab-ci-multi-runner

MIT License
146 stars 86 forks source link

Docker executor couldn't connect to the local gitlab #38

Closed Robin2009 closed 7 years ago

Robin2009 commented 7 years ago

My case is simply to host a gitlab and a CI runner together inside of my local docker on my mac. I can see the runner is recognized by gitlab but it looks like the runners docker is unable to fetch repository from it. I'd been searching a lot but just can't fix my problem. I guess it's due to the network settings of the "temp" container created by my runner container. Here's my .yml file which's aiming to create a self-hosted gitlab & gitlab-runner. Hope anyone has any idea to help me to get it work.

version: '2'

services:
  gitlab:
    image: 'gitlab/gitlab-ce:latest'
    container_name: 'gitlab'
    restart: always
    hostname: 'gitlab.local.com'   # I just add this domain name locally in my etc/hosts file
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'http://gitlab.local.com:80'
        gitlab_rails['gitlab_shell_ssh_port'] = 22
    ports:
      - '80:80'
      - '22:22'
    volumes:
      - ‘/somewhere-on-my-mac/config:/etc/gitlab'
      - '/somewhere-on-my-mac/logs:/var/log/gitlab'
      - '/somewhere-on-my-mac/data:/var/opt/gitlab'

  node-runner:
    container_name: 'gitlab-runner-node'
    image: sameersbn/gitlab-ci-multi-runner
    volumes:
      - /somewhere-on-my-mac/node-runner/data:/home/gitlab_ci_multi_runner/data
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      - CI_SERVER_URL=http://gitlab/ci
      - RUNNER_TOKEN=myTokenCode
      - RUNNER_DESCRIPTION=NODE CI RUNNER
      - RUNNER_EXECUTOR=docker
      - DOCKER_IMAGE=node:7-slim
    restart: always
    links:
      - gitlab

CI thrown messages like this:

gitlab-ci-multi-runner 1.1.4 (9e2fd1a)
Using Docker executor with image node:7-slim ...
Pulling docker image node:7-slim ...

Running on runner-feee1e28-project-2-concurrent-0 via c21641d594e3...
Cloning repository...
Cloning into '/builds/Robin/ci-demo'...
fatal: unable to access 'http://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@gitlab.local.com/Robin/ci-demo.git/': Failed to connect to gitlab.local.com port 80: Connection refused

ERROR: Build failed: exit code 1

with adding the links = [gitlab] into the [runners.docker] section I got this instead:

gitlab-ci-multi-runner 1.1.4 (9e2fd1a)
Using Docker executor with image node:7-slim ...
Pulling docker image node:7-slim ...

ERROR: Build failed: API error (500): Cannot link to /gitlab, as it does not belong to the default network
digitalLumberjack commented 7 years ago

The issue is you have the gitlab.local.com entry only in your /etc/hosts.

Just use gitlab in place of gitlab.local.com in /etc/hosts and in the gitlab configuration, and the resolution will be the same in the runner context and on your desktop.

Robin2009 commented 7 years ago

Hi @digitalLumberjack , thanks for your kind response so much. If my understanding is right, then according to your suggestion, those what I should change:

  1. change 127.0.0.1 gitlab.local.com to 127.0.0.1 gitlab in /etc/hosts on my mac
  2. replace gitlab.local.com with gitlab in my docker-compose.yml file

I will try it soon once I get my mac in hand. One more question, in that case, is the links: -gitlab still necessary for me?