<p>I am using the docker dind image and creating a  pod. When I try to run docker build inside the pod, I get an error.</p>
<pre class="lang-yaml prettyprint-override"><code>    apiVersion: v1
    kind: Pod
    metadata:
      name: dockercontainer
      namespace: default
    spec:
      containers:
      - image: docker:24.0.0-rc.1-dind
        name: dockercontainer
        securityContext:
          runAsUser: 0
</code></pre>
<p>The pod is getting created, but when I execute a docker build inside the pod, I get the following error:
<code>ERROR: Cannot connect to the docker daemon at unix://var/run/docker.sock</code></p>
<p><a href="https://i.stack.imgur.com/4dava.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4dava.png" alt="enter image description here" /></a></p>

Hanuman
<p><strong>NOTE</strong>: this assumes that you're using a docker runtime in K8s! If not, use <a href="https://github.com/agavitalis/kaniko-kubernetes" rel="nofollow noreferrer">kaniko</a>.</p>
<p>The docker daemon isn't mounted into the pod - this is the reason for your error. In order to build images, you will need one of these:</p>
<ul>
<li>get the docker daemon mounted into each container of the pod</li>
<li>run the containers in the pod in <code>privileged</code> mode</li>
</ul>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: dockercontainer
  namespace: default
spec:
  containers:
  - image: docker:24.0.0-rc.1-dind
    name: dockercontainer
    securityContext:
      privileged: true # this should do the trick
</code></pre>
<p>There are some issues w/ building/running containers w/in a K8s pod, <strong>from a security standpoint</strong> (more on this <a href="https://kurtmadel.com/posts/native-kubernetes-continuous-delivery/building-container-images-with-kubernetes/" rel="nofollow noreferrer">here</a> and <a href="https://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/" rel="nofollow noreferrer">here</a>). Much safer approach is to use <a href="https://github.com/nestybox/sysbox" rel="nofollow noreferrer">sysbox</a> but that's perhaps more detailed than we want to get here.</p>
<p>I'm assuming that it's not possible for you to be able to build this image outside of K8s.</p>
