<p>I'm using a docker image that has docker installed inside it, in order to run tasks to cleanup docker image data on every node in my kubernetes cluster. I tried using Daemonset as it will run on each node except master, but running cron inside docker container proved fruitless.</p>
<p>Hence, I'm trying to use a K8s Cronjob, that runs periodically, with the attributes:</p>
<p><code>hostNetwork: true</code></p>
<p>and</p>
<pre><code>      volumes:
        - name: dockersocket
          hostPath:
            path: /var/run/docker.sock
</code></pre>
<p>I'm running a shell script that runs docker commands from within the container created by the above CronJob.</p>
<p>However, When i try and get all images running on a node of the kubernetes cluster using <code>docker -H X.X.X.X images</code> where X.X.X.X is the IP of one node in the k8s cluster, I get the following error:</p>
<p><code>Cannot connect to the Docker daemon at tcp://X.X.X.X:2375. Is the docker daemon running?</code></p>
<p>Am I doing something wrong?
How do I connect to Docker running on the nodes of the kubernetes cluster from a container running inside the kubernetes cluster?</p>

hisdudeness
<p><a href="https://rpg.meta.stackexchange.com/questions/6842/whats-a-frame-challenge/6843#6843">Frame challenge</a>: what you're doing is not the right approach.</p>
<p>Trying to access the underlying Docker in a Kubernetes cluster is <em>usually</em> viewed as a bad idea, as it can easily result in a corrupt state that's difficult to repair.</p>
<p>Kubelet has <a href="https://kubernetes.io/docs/concepts/cluster-administration/kubelet-garbage-collection/" rel="nofollow noreferrer">built-in garbage collection</a>. Why not tweak the configuration for that instead?</p>
<p>If you're running on one of the big PaaS providers, your node turnover will likely be high enough (from auto-upgrades/whatever else) that this isn't an issue regardless.</p>
