ERROR: Failed to remove network for build

I have installed gitlab-runner via docker in my server with this command:

docker exec -it gitlab-runner gitlab-runner register \
--non-interactive \
--url "http://gitlab.aloghesti.local" \
--registration-token "glrt-v5YDsxuazYRUXMXRsuWU" \
--executor "docker" \
--docker-image docker:latest \
--docker-tlsverify="false" \
--docker-privileged="false" \
--docker-volumes='/var/run/docker.sock:/var/run/docker.sock' \
--docker-volumes='/cache' \
--description "aloghesti-runner" \
--tag-list "docker.sock,imac" \
--run-untagged="true" \
--locked="false" \
--access-level="not_protected"

But whenever run my jobs I get this error:

Running with gitlab-runner 16.5.0 (853330f9)
  on aloghesti-runner v5YDsxuaz, system ID: r_qfj6n9LoVjcy
Preparing the "docker" executor
ERROR: Failed to remove network for build
ERROR: Preparation failed: error during connect: Get "http://docker:2375/v1.24/info": dial tcp: lookup docker on 8.8.8.8:53: no such host (docker.go:826:0s)
Will be retried in 3s ...
ERROR: Failed to remove network for build
ERROR: Preparation failed: error during connect: Get "http://docker:2375/v1.24/info": dial tcp: lookup docker on 8.8.8.8:53: no such host (docker.go:826:0s)
Will be retried in 3s ...
ERROR: Failed to remove network for build
ERROR: Preparation failed: error during connect: Get "http://docker:2375/v1.24/info": dial tcp: lookup docker on 8.8.8.8:53: no such host (docker.go:826:0s)
Will be retried in 3s ...
ERROR: Job failed (system failure): error during connect: Get "http://docker:2375/v1.24/info": dial tcp: lookup docker on 8.8.8.8:53: no such host (docker.go:826:0s)

I do not know what is the problem and have searched so much on Google and other Ways.

Need execute command with sudo privileges, and don’t forget add privileges gitlab-runner to docker

docker exec -it gitlab-runner **sudo** gitlab-runner register ......
sudo usermod -aG docker $USER
sudo usermod -aG docker gitlab-runner

if you want do this more secure way

Option 1: Using system level service

  1. Install gitlab multi runner systemwide: Install GitLab Runner | GitLab
  2. Register the runner as an unpriviledged user (paste the secret key in your repo’s runners page). This should create your configuration config (toml) file. gitlab-runner register
  3. Register the service as root user by passing the path to the toml file and the user flag and the service name (needs to be unique per user or runner).

gitlab-runner install --config /home/myuser/.gitlab-runner/config.toml --user myuser --working-directory /home/myuser --service myuser_gitlabrunner

  1. As root, run service myuser_gitlabrunner start. The process should also start on boot (it should be in /etc/init/ folder or similar, depending on your distro.)

Option 2: Using a supervisor process like supervisord

  1. Install gitlab multi runner systemwide.
  2. Register the runner as unpriviledged user. This should create your configuration toml file. gitlab-runner register
  3. Run the process as normal user. No need to pass toml file or service name. Example supervisord script:
[program:myuser_runner]
command=gitlab-runner run
directory=/home/foo
user=foo
numprocs=1
  1. As root or as a user who can manage supervisord, run supervisorctl myuser_runner start. The process should also start on boot.