Reputation: 1307
I am running GitLab and Gitlab-Runner docker instances locally. When a Spring Boot and Maven project pipeline is executed, I am getting below error.
Getting source from Git repository
00:02
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in /builds/root/starter-springboot-pipeline/.git/
fatal: unable to access 'http://localhost/root/starter-springboot-pipeline.git/': Failed to connect to localhost port 80: Connection refused
Uploading artifacts for failed job
00:07
ERROR: Job failed: exit code 1
Not sure if the localhost in the above error is referring to GitLab container or Runner container. Should it refer to the gitlab container and not the localhost?
Below are the commands and configuration I used.
Start the GitLab server:
docker run -itd --network=gitlab-network --hostname localhost \
--publish 443:443 --publish 80:80 --publish 22:22 \
--name gitlab --restart always --volume config:/etc/gitlab \
--volume logs:/var/log/gitlab \
--volume data:/var/opt/gitlab \
gitlab/gitlab-ee:12.10.14-ee.0
Start the GitLab Runner
docker run -d --name gitlab-runner --restart always \
-v ~/gitlab/gitlab-runner/config:/etc/gitlab-runner \
-v /var/run/docker.sock:/var/run/docker.sock \
gitlab/gitlab-runner:v12.10.3
Created Network 'gitlab-network' and added both containers to it.
docker network connect gitlab-network gitlab
docker network connect gitlab-network gitlab-runner
Registered the Runner as below:
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
http://gitlab
Please enter the gitlab-ci token for this runner:
XxXXxXXXxxXXXXXX
Please enter the gitlab-ci description for this runner:
[49ad685039ad]: runner14
Please enter the gitlab-ci tags for this runner (comma separated):
docker
Registering runner... succeeded runner=EkWnb63h
Please enter the executor: docker-ssh, parallels, shell, virtualbox, docker+machine, kubernetes, custom, docker, ssh, docker-ssh+machine:
docker
Please enter the default Docker image (e.g. ruby:2.6):
alpine:latest
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
Below is the gitlab-ci.yml
image: maven:3.3-jdk-8
stages:
- test
test_job:
stage: test
script:
- pwd
- mvn clean
- mvn compile
- mvn test
tags:
- docker
I have newly started working on GitLab and docker, able to setup them and run the pipeline after resolving some issues with good amount of research. But I am stuck with this issue.
Upvotes: 1
Views: 6292
Reputation: 5053
Hostname localhost
is always resolved to 127.0.0.1
or ::1
- in other words to the loopback interface, which as the name suggests loops back and connects to itself.
This means that your runner is trying to find http://localhost/root/starter-springboot-pipeline.git/
inside its own container - which obviously fails because it's in GitLab's container.
It's also why, in your runner config, you had to specify GitLab's address as http://gitlab
and not as http://localhost
You might try starting the GitLab container with command (recreate named volumes beforehand to ensure it's configured from scratch)
docker run -itd --network=gitlab-network --hostname gitlab \
--publish 443:443 --publish 80:80 --publish 22:22 \
--name gitlab --restart always \
--env GITLAB_OMNIBUS_CONFIG="external_url 'http://gitlab/'" \
--volume config:/etc/gitlab \
--volume logs:/var/log/gitlab \
--volume data:/var/opt/gitlab \
gitlab/gitlab-ee:12.10.14-ee.0
but I can't guarantee it'll work, as GitLab was designed to run on servers that have their own unique hostname.
Edit:
You may also try editing config.toml
and setting network_mode
in [runners.docker]
section to gitlab-network
. See here for more info.
Upvotes: 3