Docker in GitLab CI misbehaving
If you’re encountering the following error in your GitLab CI/CD pipeline logs:
error during connect: Get "http://docker:2375/v1.51/info": dial tcp: lookup docker on <ip_edited>:53: server misbehaving
…then there’s a high chance you’re trying to use Docker-in-Docker.
The root cause of this error usually lies in the GitLab Runner configuration—specifically, the network_mode
setting in the config.toml
file. If you’ve manually configured network_mode
, that setting may be interfering with Docker’s ability to resolve the docker hostname used for communicating with the Docker daemon.
In most cases, removing the network_mode line entirely from your runner’s config.toml resolves the issue. GitLab Runner, by default, creates a dedicated Docker network for each job, which ensures proper DNS resolution and communication between containers (including the Docker daemon). When you override this behavior with a custom network mode, it can break that isolation or prevent expected name resolution.
So, go to your runner’s configuration file (usually it is located at /etc/gitlab-runner/config.toml
), and remove or comment out any line like this:
[[runners]]
executor = "docker"
[runners.docker]
network_mode = "host" <-- this is line which you should remove
Normaly GitLab runner doesn't require restart but, it is nice to have anyway, so as a reminder:
service gitlab-runner restart
For more detailed information, refer to the official GitLab documentation:
- https://docs.gitlab.com/runner/executors/docker/#create-a-network-for-each-job