<p>Is there a recommended way of initiating 'docker build' commands from a container loaded in to Kubernetes?</p>

<p>IE. Spinning up a Jenkins container (from the community image) and then ensuring that docker is installed within that container so you can issue 'docker build' commands.</p>

<p>I've read up on various methods such as DIND (Docker in Docker) containers and running links between the Jenkins container and the DIND container. Of course with Kubernetes this would be different.</p>

<p>There are two ways of accessing docker daemon from a Kubernetes Pod. </p>

<ol>
<li><p>You can expose the docker daemon running on the host machine (this is the docker daemon used by kubernetes to spin up your container) inside your container. To do this you need to modify your Pod specification to add a hostPath for the docker daemon socket (typically <code>/var/run/docker.sock</code>). Now, you can install docker inside your container and access the docker daemon of the host machine. </p></li>
<li><p>The second method is using Docker-in-Docker (DinD). In this method, you can use the concept of a <a href="http://blog.kubernetes.io/2015/06/the-distributed-system-toolkit-patterns.html" rel="noreferrer">sidecar container</a> to run the docker in docker daemon. The main container in the pod will have to be configured to talk to the docker daemon in the sidecar container. You can do this by setting an environment variable <code>DOCKER_HOST</code> to <code>tcp://localhost:2375</code>. You can find the complete Pod specification and a lot more details on the differences between the two approaches on my <a href="https://applatix.com/case-docker-docker-kubernetes-part-2/" rel="noreferrer">blog article about DinD on Kubernetes</a></p></li>
</ol>
