<p>I want to <a href="https://docs.docker.com/engine/reference/commandline/image_prune/" rel="noreferrer">prune</a> docker images, I wrote a small Docker image using <code>node-docker-api</code> and I was able to test it locally with success.<br>
As I've deployed the <code>DaemonSet</code> to Kubernetes, the pod fails to access the Docker socket:</p>

<pre><code>Error: connect EACCES /var/run/docker.sock
</code></pre>

<p>The <code>deployment.yaml</code> looks as following:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
  labels:
    name: docker-image-cleanup
  name: docker-image-cleanup
spec:
  template:
    metadata:
      labels:
        app: docker-image-cleanup 
    spec:
      volumes:
        - name: docker-sock
          hostPath:
            path: "/var/run/docker.sock"
            type: File
        - name: docker-directory
          hostPath:
            path: "/var/lib/docker"

      containers:
        - name: docker-image-cleanup
          image: image:tag
          securityContext:
            privileged: true
          env:
            - name: PRUNE_INTERVAL_SECONDS
              value: "30"
            - name: PRUNE_DANGLING
              value: "true"
          volumeMounts:
            - mountPath: /var/run/docker.sock
              name: docker-sock
              readOnly: false
            - mountPath: "/var/lib/docker"
              name: docker-directory
              readOnly: false
</code></pre>

<p>Running AKS v1.13.10 - if relevant </p>

SagiLow
<p>There is no guarantee that your kubernetes cluster is actually using docker as container engine. As there are many alternatives like cri-o and kata containers your application/deployment should make no assumptions about the underlying container engine.</p>

<p>Kubernetes takes care about cleaning up unused container images automatically. See documentation on how to configure it, if you run the cluster yourself: <a href="https://kubernetes.io/docs/concepts/cluster-administration/kubelet-garbage-collection/" rel="noreferrer">https://kubernetes.io/docs/concepts/cluster-administration/kubelet-garbage-collection/</a></p>

<p>Aside from that it looks like you have a simple permission problem with the socket: Make sure your application in the cleanup container runs as root or has appropriate user to access the socket.</p>
