Docker executor jobs cannot resolve the GitLab host when they clone
Fix it fast
Most common cause, 1 of 2The GitLab name is a Compose service name that job containers cannot see
Attach job containers to the Compose network, using the existing network's name, or give the runner a clone_url that job containers can reach from the bridge, such as the host's LAN address.
# /etc/gitlab-runner/config.toml
[[runners]]
url = "http://gitlab"
# option A: a clone address reachable from the default bridge
clone_url = "http://192.168.1.20:8080"
[runners.docker]
# option B: run jobs on the Compose network where "gitlab" resolves
network_mode = "myproject_default"Short answer
A GitLab Runner Docker executor job that fails to clone with Could not resolve host runs in a container that cannot look up the GitLab name. Jobs use Docker's default bridge network, which knows neither Compose service names nor the host's /etc/hosts entries. Set clone_url, attach jobs with network_mode, or add extra_hosts. Applies to GitLab Runner 19.
Which cause do you have?
Find out where the GitLab name in the error resolves today. If it is a Compose service name, cause 1 applies. If it only works because of a line in the runner host's /etc/hosts, cause 2 applies. A throwaway container on the default bridge shows what job containers see.
# runner in a container: docker exec gitlab-runner grep ... /etc/gitlab-runner/config.toml
grep -n -E "^[[:space:]]*(url|clone_url|network_mode|extra_hosts)" /etc/gitlab-runner/config.toml
grep -n "gitlab" /etc/hosts
docker run --rm alpine nslookup gitlab.example.internalThen find the line you see in this list and open its fix:
- 1The GitLab name is a Compose service name that job containers cannot see
GitLab and the runner run in one docker compose project, url in config.toml is http://gitlab (the service name), and network_mode is not set - 2The GitLab name exists only in the runner host's /etc/hosts
The host resolves the name through an /etc/hosts line, but nslookup from a fresh container fails
What does the error look like?
Could not resolve host: gitlabCould not resolve host: gitlab.example.internal
Cause 1 of 2
The GitLab name is a Compose service name that job containers cannot see
You seeGitLab and the runner run in one docker compose project, url in config.toml is http://gitlab (the service name), and network_mode is not set
Check
Compose attaches its services to a network named <project>_default, and only containers on that network can find a service by its name. The Docker executor starts each job container on the default bridge network unless network_mode says otherwise, and on that network containers cannot refer to each other by name. The runner itself reaches http://gitlab, but the clone inside the job container cannot resolve it.
docker network ls --filter name=_default
docker inspect gitlab --format '{{json .NetworkSettings.Networks}}'Fix
Attach job containers to the Compose network, using the existing network's name, or give the runner a clone_url that job containers can reach from the bridge, such as the host's LAN address. The runner reloads config.toml on its own within seconds.
# /etc/gitlab-runner/config.toml
[[runners]]
url = "http://gitlab"
# option A: a clone address reachable from the default bridge
clone_url = "http://192.168.1.20:8080"
[runners.docker]
# option B: run jobs on the Compose network where "gitlab" resolves
network_mode = "myproject_default"Verify
Retry the pipeline. The job log shows the repository fetched and the job continues to its script.
docker run --rm --network myproject_default alpine nslookup gitlabConfirmed by docs.gitlab.com
Cause 2 of 2
The GitLab name exists only in the runner host's /etc/hosts
You seeThe host resolves the name through an /etc/hosts line, but nslookup from a fresh container fails
Check
An internal GitLab name without a DNS record may exist only as a line in /etc/hosts on the runner machine. Docker passes the host's resolv.conf DNS settings to containers, but its networking guide states that custom entries in the host's /etc/hosts are not inherited. Job containers therefore ask the DNS server, which has never heard of the name.
docker run --rm alpine cat /etc/hostsFix
Give job containers the same mapping with extra_hosts, point the runner at a DNS server that knows the name with dns, or create a real DNS record. clone_url with an IP address also works when only the clone fails.
# /etc/gitlab-runner/config.toml
[[runners]]
[runners.docker]
extra_hosts = ["gitlab.example.internal:192.168.1.20"]
# or a resolver that has the record
# dns = ["192.168.1.2"]Verify
A container started with the same mapping resolves the name, and the next job clones.
docker run --rm --add-host gitlab.example.internal:192.168.1.20 alpine nslookup gitlab.example.internalConfirmed by docs.docker.com
How do I stop it coming back?
- Register runners with a GitLab address that resolves in DNS, not one that exists only inside a Compose project or a hosts file.
- Keep url, clone_url and the [runners.docker] network settings in version control next to the Compose file, so a recreated runner keeps them.
- When GitLab and the runner share a Compose project, set network_mode to the project network on purpose and note the project name, because renaming the folder changes the network name.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: TaxiDex, Dispatch Pro.