How to fix gitlab pipeline error: docker error: error during connect: Get “http://docker:2375/v1.24/images/json”: dial tcp: lookup docker on 127.0.0.53:53: server misbehaving

  devops, linux
The error:

error during connect: Get "http://docker:2375/v1.24/images/json": dial tcp: lookup docker on 127.0.0.53:53: server misbehaving
ERROR: Job failed: exit code 1


# Edit the gitlab runner:

sudo nano /etc/gitlab-runner/config.toml

# change the line:
volumes = ["/cache"]

# to
volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]


# also make sure you have this line:
privileged = true


# example /etc/gitlab-runner/config.toml contents:

concurrent = 1
check_interval = 0
shutdown_timeout = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "gitlab"
  url = "http://172.17.0.1/ci"
  id = 74
  token = "glrt-............"
  token_obtained_at = 2023-08-26T18:27:30Z
  token_expires_at = 0001-01-01T00:00:00Z
  executor = "docker"
  [runners.cache]
    MaxUploadedArchiveSize = 0
  [runners.docker]
    tls_verify = false
    image = "docker:stable"
    privileged = true
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]
    network_mode = "host"
    shm_size = 0


# run the gitlab pipeline again


# Or, a command line search and replace fix:
sed -i 's+    volumes = \["\/cache"\]+    volumes = \["\/cache", "\/var\/run\/docker.sock:\/var\/run\/docker.sock"\]+g' config.toml