0

I've been tearing my hair out for a few days trying to find a solution.

My gitlab runner is unable to connect to git repos with the error: fatal: unable to access 'https://gitlab.com/project.git/': Could not resolve host: gitlab.com

I tried several solutions:

  • restart docker: sudo systemctl daemon
  • reload creation of a new runner
  • changed the docker image

But I think the problem comes from the DNS of my machine (debian ovh) and I don't know how to solve it.

In effect,

my ci cd is:

stages:
- docker

back:docker:
  stage: docker
  tags:
    - wellcov-runner
  image: docker:latest
  services:
    - docker:dind
  before_script:
  - echo -n $MAIN_REGISTRY_PASSWORD | docker login -u $MAIN_REGISTRY_USER --password-stdin $CI_REGISTRY
  variables:
    # Pushing into the shared Wellcov container registry (main repository)
    IMAGE: $MAIN_REGISTRY/wellcov-back-end:$CI_COMMIT_REF_NAME
  cache:
    paths:
    - target/
  script:
  - echo "Gitlab CI - Building back-end ${CI_COMMIT_REF_NAME} docker"
  - docker build -t $IMAGE . --build-arg MAVEN_IMAGE=$MAVEN_IMAGE --build-arg UBI_IMAGE=$UBI_IMAGE
  - docker push $IMAGE

the runner parameters:

concurrent = 1
check_interval = 0
shutdown_timeout = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "wellcov-runner"
  url = "https://gitlab.com/"
  id = 22344137
  token = "...."
  token_obtained_at = 2023-04-01T17:10:09Z
  token_expires_at = 0001-01-01T00:00:00Z
  executor = "docker"
  [runners.cache]
    MaxUploadedArchiveSize = 0
  [runners.docker]
    tls_verify = false
    image = "ruby:2.7"
    privileged = false
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]
    shm_size = 0

I also suspect that the port of the container is not 8093/tcp like that of the service

should I add a dnas rule to iptables or update the container so that it runs on port 8093/tcp

docker service ls :

ID             NAME                              MODE         REPLICAS   IMAGE
x4lq3jnshtii   gitlab_runner                     replicated   1/1        gitlab/gitlab-runner:latest                                            ***:8093->8093/tcp**

Docker container ls

CONTAINER ID   IMAGE                                                                  COMMAND                  CREATED        STATUS                  PORTS      NAMES
652d53ee4780   gitlab/gitlab-runner:latest                                            "/usr/bin/dumb-init …"   14 hours ago   Up 14 hours                        gitlab_runner.1.m3wt71h3f5eldppib83j3uvzj

Thanks for your help

djecko06
  • 1
  • 1

1 Answers1

0

Solution one:

Restart your docker instance. Ex: systemctl restart docker. This might fix it as seen with similar cases. Also happened to me once.


Solution two:

Check your repository permissions, it might be an issue with that rather than docker. It could be missing access or miss-configuration etc.

Might be something firewall related.


Solution 3

There is a setting you can pass in the gitlab-runner's config.toml:

[[runners]]
...
  [runners.docker]
    network_mode= <----- THIS

This setting will tell gitlab-runner which network to place the container in when it gets spun up, so if you know the name of the network your gitlab and gitlab-containers run on:

docker inspect --format='{{.NetworkSettings.Networks}}' <gitlab container id>

then add that as the network mode (in this case the network name is going to be git-lab_default for the sake of it. Change it out for whatever you have):

[[runners]]
...
  [runners.docker]
    network mode= "git-lab_default"

If the above fails, leave a comment.

Sources:
#47283 | gitlab-foss
#6644 | gitlab-runner

SimpleCoder
  • 474
  • 4
  • 18