Gitlab CI/CD Fatal Can't Access Localhost Error

Describe your question in as much detail as possible:
Hey all - any help would be greatly appreciated! GitLab noob here.

When I expect to see the rest of the .gitlab-ci.yml take place. It’s the template from the CI/CD tutorial, nothing that I wrote. The issue is that my runner can’t seem to access my localhost. Both my GitLab instance and my GitLab-runners are docker containers. I’m under the impression that when a runner is used a docker container then it creates its own docker instance so it makes sense to me that of course it couldn’t connect to my localhost, but I cannot seem to get it to connect to my localhost, which would be my GitLab server.

  • Consider including screenshots, error messages, and/or other helpful visuals

  • What version are you on? Are you using self-managed or GitLab.com?
    Self managed

    • GitLab (Hint: /help): 13.11.4-ee
    • Runner (Hint: /admin/runners): 13.12.0
  • Add the CI configuration from .gitlab-ci.yml and other configuration if relevant (e.g. docker-compose.yml)
    docker-compose.yml:

web:
  image: 'gitlab/gitlab-ee:latest'
  restart: always
  hostname: 'http://localhost:8929'
  environment:
    GITLAB_OMNIBUS_CONFIG: |
      external_url 'http://localhost:8929'
      gitlab_rails['gitlab_shell_ssh_port'] = 2224
  ports:
    - '8929:8929'
    - '2224:22'
  volumes:
    - '$GITLAB_HOME/config:/etc/gitlab'
    - '$GITLAB_HOME/logs:/var/log/gitlab'
    - '$GITLAB_HOME/data:/var/opt/gitlab'
  • What troubleshooting steps have you already taken? Can you link to any docs or other resources so we know where you have been?
    I’ve tried a couple different things.
    I have tried to add an alias in config.toml to see if I needed to alias my localhost so it can be seen by my runner. I turned my GitLab off and modified my docker-compose.yml to change the external url as can be seen in my document up top. I haven’t been too successful with either option.

EDIT: Might I add – I can git clone http://localhost:8929/root/simple-ci-cd.git/ with zero issues in the console. So this further leads me to believe that the containerized runner just simply can’t see my gitlab container.

Hi @jmachcse
you can’t use localhost as hostname, because localhost is a separate thing in each container and GitLab Runner is trying to connect to it’s own container localhost.
Use IP of your server/pc or some other domain.

Hi @balonik
Thanks for the reply!
Unfortunately, this hasn’t worked for me. Now, in place of where hostname was, it has changed to 127.0.1.1 which is the address of my GitLab instance.
I’ve made a second Ubuntu VM as a testing environment where I have GitLab running on its own (not in a Docker container) and I have GitLab-Runner running as a Docker container. In this instance I am also having trouble registering runners under the GitLab-Runner docker container. I get this error here

ERROR: Registering runner... failed                 runner=vgjSysey status=couldn't execute POST against http://jeremy-virtualbox/api/v4/runners: Post http://jeremy-virtualbox/api/v4/runners: dial tcp: lookup jeremy-virtualbox on 102.0.30.1:53: read udp 172.17.0.3:58939->102.0.30.1:53: i/o timeout
PANIC: Failed to register the runner. You may be having network problems.

Any further advice is greatly appreciated!

I think I’ve got an idea but I’m not sure how to do it properly.

Since I want to use the Docker executor, I understand that when the executor is created it creates a new container in Docker that’s self contained. So, is there a way I can pass something like --network=host to the new docker container so the Docker container executor can recognize my GitLab repo as a valid link?

I’ve drawn a picture to better explain what I mean because I fear I’m not articulating exactly what I mean. I apologize for the handwriting, I am no penman!

127.0.0.0/8 is still localhost and not routed outside. You can’t use any IP from range 127.0.0.0/8 for services that should be reachable from external sources.

Gotcha. It looks like I was able to figure it out a completely different way. I used the extra_hosts option in config.toml. That allowed my runner to see my git repo and successfully cloned & completed my test job!
Thanks for your help! Looks like I need to increase my Google-fu skills :wink:

What did you set into external host?