Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Servers, nginx and Docker

The docker:dind service dies in GitLab CI because docker.sock is already mounted

Your error

failed to load listeners: can't create unix socket /var/run/docker.sock: device or resource busy1 more line it can show

Fix it fast

Most common cause, 1 of 2

A Docker executor runner mounts the host socket and the job adds docker:dind

Pick one method for this runner.

Fix
# /etc/gitlab-runner/config.toml (dind runner)
[runners.docker]
  image = "docker:29.10.0-cli"
  privileged = true
  volumes = ["/certs/client", "/cache"]

# .gitlab-ci.yml
default:
  image: docker:29.10.0-cli
  services:
    - docker:29.10.0-dind
  before_script:
    - docker info
variables:
  DOCKER_TLS_CERTDIR: "/certs"
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

failed to load listeners: can't create unix socket /var/run/docker.sock: device or resource busy appears when a job starts the docker:dind service on a runner that already bind-mounts the host's /var/run/docker.sock. GitLab documents the two methods as incompatible. Remove the socket volume from that runner or drop the dind service. Applies to GitLab Runner 19.x with Docker 29.

  • Applies to GitLab Runner 19.6 (Docker and Kubernetes executors), docker:29.10.0-dind and docker:29.10.0-cli images
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Open the runner's configuration and look for two things: which executor it uses, and whether docker.sock appears among its volumes or host_path mounts. The executor line decides which cause below applies.

Run this first
sudo grep -n -E 'executor|docker.sock|host_path|mount_path' /etc/gitlab-runner/config.toml

Then find the line you see in this list and open its fix:

  1. 1A Docker executor runner mounts the host socket and the job adds docker:dindexecutor = "docker" and a volumes list that includes /var/run/docker.sock:/var/run/docker.sock
  2. 2A Kubernetes executor runner has a host_path mount at /var/run/docker.sockThe Helm values or config.toml hold a [[runners.kubernetes.volumes.host_path]] block with mount_path = '/var/run/docker.sock'

What does the error look like?

  • failed to load listeners: can't create unix socket /var/run/docker.sock: device or resource busy
  • docker: Cannot connect to the Docker daemon at tcp://docker:2375. Is the docker daemon running?

Cause 1 of 2

A Docker executor runner mounts the host socket and the job adds docker:dind

You seeexecutor = "docker" and a volumes list that includes /var/run/docker.sock:/var/run/docker.sock

Check

The device or resource busy message on /var/run/docker.sock means the dind daemon wants to create its own socket at a path the runner has already filled with the host's socket. GitLab's Docker build guide says a runner that binds the socket cannot run the dind service, because volume bindings reach service containers too.

Check
grep -n -B2 -A2 'dind' .gitlab-ci.yml

Fix

Pick one method for this runner. For dind, remove the socket from volumes, set privileged = true, mount /certs/client and keep DOCKER_TLS_CERTDIR. For socket binding, delete the services entry and any DOCKER_HOST variable so the client uses the host daemon.

Fix
# /etc/gitlab-runner/config.toml (dind runner)
[runners.docker]
  image = "docker:29.10.0-cli"
  privileged = true
  volumes = ["/certs/client", "/cache"]

# .gitlab-ci.yml
default:
  image: docker:29.10.0-cli
  services:
    - docker:29.10.0-dind
  before_script:
    - docker info
variables:
  DOCKER_TLS_CERTDIR: "/certs"

Verify

The job log shows a Server section from the dind daemon when docker info runs, and the listener failure is gone from the service output.

Verify
docker info

Confirmed by docs.gitlab.com

Did this fix it?

Cause 2 of 2

A Kubernetes executor runner has a host_path mount at /var/run/docker.sock

You seeThe Helm values or config.toml hold a [[runners.kubernetes.volumes.host_path]] block with mount_path = '/var/run/docker.sock'

Check

On the Kubernetes executor, every volume given to the build container is also mounted into each service container. A host_path mount for docker.sock therefore lands inside the dind service as well, and the daemon there cannot claim that path.

Check
grep -n -A4 'host_path' values.yaml

Fix

Remove the host_path socket block from runners that serve dind jobs. Give them an in-memory empty_dir for /certs/client, run privileged, and point the client at the service over TLS on port 2376.

Fix
# values.yaml -> runners.config
[[runners]]
  [runners.kubernetes]
    privileged = true
    [[runners.kubernetes.volumes.empty_dir]]
      name = "docker-certs"
      mount_path = "/certs/client"
      medium = "Memory"

# .gitlab-ci.yml variables for the job
DOCKER_HOST: tcp://docker:2376
DOCKER_TLS_CERTDIR: "/certs"
DOCKER_TLS_VERIFY: 1
DOCKER_CERT_PATH: "$DOCKER_TLS_CERTDIR/client"

Verify

The dind service container reaches running state in the job pod, and docker info answers through tcp://docker:2376.

Verify
kubectl get pods --namespace gitlab-runner --watch

Confirmed by docs.gitlab.com

Did this fix it?

How do I stop it coming back?

  • Tag dind runners and socket-binding runners differently, and put the matching tag on every job, so a dind job never lands on a socket runner.
  • When concurrent dind jobs need a Unix socket, share a temporary /runner/services/docker volume and set DOCKER_HOST to unix:///runner/services/docker/docker.sock instead of reusing /var/run.
  • Pin the dind service and the cli image to the same Docker version in .gitlab-ci.yml.

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: Dispatch Pro, TaxiDex.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.