<p>I am trying to get docker running on Jenkins which itself is a container. Below is part of the Pod spec.</p>
<p><code>cyrilpanicker/jenkins</code> is an image with Jenkins and docker-cli installed.
For Docker daemon, I am running another container with <code>docker:dind</code> image (The nodes are running on a k8s cluster).
And to get <code>docker.sock</code> linked between them, I am using volume mounts.</p>
<pre><code>spec:
  containers:
    - name: jenkins
      image: cyrilpanicker/jenkins
      volumeMounts:
        - mountPath: /var/run/docker.sock
          name: docker-socket
    - name: docker
      image: docker:dind
      securityContext:
        privileged: true
      volumeMounts:
        - mountPath: /var/run/docker.sock
          name: docker-socket
  volumes:
    - name: docker-socket
      hostPath:
        path: /docker.sock
        type: FileOrCreate
</code></pre>
<p>But this is not working. Below are the logs from the <code>docker</code> container.</p>
<pre><code>time=&quot;2021-06-04T20:47:26.059792967Z&quot; level=info msg=&quot;Starting up&quot;
time=&quot;2021-06-04T20:47:26.061956820Z&quot; level=warning msg=&quot;could not change group /var/run/docker.sock to docker: group docker not found&quot;
failed to load listeners: can't create unix socket /var/run/docker.sock: device or resource busy
</code></pre>
<p>Can anyone suggest another way to get this working?</p>

Cyril
<p>According to the kubernetes docs, <code>hostPath</code> mounts a path from node filesystem, so if I understand correctly, this is not what you want to achieve.
I'm afraid that it isn't possible do mount single file as a volume, so even if you remove <code>hostPath</code> from <code>volumes</code>, <code>docker.sock</code> will be mounted as directory:</p>
<pre><code>jenkins@static-web:/$ ls -la /var/run/
total 20
drwxr-xr-x 1 root root 4096 Jun  5 14:44 .
drwxr-xr-x 1 root root 4096 Jun  5 14:44 ..
drwxrwxrwx 2 root root 4096 Jun  5 14:44 docker.sock
</code></pre>
<p>I would try to run docker daemon in dind container with TCP listener instead of sock file:</p>
<pre><code>spec:
  containers:
    - name: jenkins
      image: cyrilpanicker/jenkins
    - name: docker
      image: docker:dind
      command: [&quot;dockerd&quot;]
      args: [&quot;-H&quot;, &quot;tcp://127.0.0.1:2376&quot;]
      ports:
        - containerPort: 2376
      securityContext:
        privileged: true
</code></pre>
<pre><code>jenkins@static-web:/$ docker -H tcp://127.0.0.1:2376 ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
</code></pre>
<p>And then configure jenkins to use <code>tcp://127.0.0.1:2376</code> as a remote docker daemon.</p>
