How to fix Gitlab CI error during connect: Post http://docker:2375/v1.40/auth: dial tcp: lookup docker on … no such host

How to fix Gitlab CI error during connect: Post http://docker:2375/v1.40/auth: dial tcp: lookup docker on … no such host. I spent more than 1 hour to fix it. And I am totally not sure that I will remember it 🙂
The source is here:
This error occurs with docker-based gitlab runners such as the one we’re that are configured using a docker executor. The error message means that the inner docker container doesn’t have a connection to the host docker daemon.
In order to fix this, set these options in [runners.docker] in your gitlab-runner config.toml:
1 2 |
privileged = true volumes = ["/certs/client", "/cache"]' |

The content of /etc/gitlab-runner/config.toml is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
concurrent = 1 check_interval = 0 shutdown_timeout = 0 [session_server] session_timeout = 1800 [[runners]] name = "y docker-runner" url = "https://gitlab.com/" id = 21389039 token = "gitlab-runner-token-" token_obtained_at = 2023-02-24T09:56:32Z token_expires_at = 0001-01-01T00:00:00Z executor = "docker" [runners.cache] MaxUploadedArchiveSize = 0 [runners.docker] tls_verify = false image = "ruby:2.7" privileged = true disable_entrypoint_overwrite = false oom_kill_disable = false disable_cache = false volumes = ["/certs/client", "/cache"] shm_size = 0 |