<p>I have a kubernetes cluster that is running on AWS EC2 instances and weave as networking(cni). I have disabled the docker networking(ipmask and iptables) as it is managed by weave(to avoid network conflicts).
<br></p>

<p>I have deployed my Jenkins on this cluster as K8s pod and this jenkins uses jenkins kubernetes plugin to spawn dynamic slaves based on pod and container template which I have defined. These slaves container have docker client in it which connects to the host docker engine via docker.sock
<br></p>

<p>So when I run any job in Jenkins it starts a slave and on this it clones a git repo and starts building the Dockerfile present inside the repo. </p>

<p>My sample dockerfile looks like this:</p>

<pre><code>FROM abc:123
RUN yum update
</code></pre>

<p>So when container starts building this it tries connecting to redhat repo to update the local repo and fails here. To debug I logged in to this container and try wget/CURL some packages and finds that there is no internet connectivity in this container.</p>

<p>I suspect that while building docker starts intermediate containers and those containers are not managed by weave so they do not have internet connectivity.
<br></p>

<p>Need suggestions.
<br></p>

<p>Related question: <a href="https://stackoverflow.com/questions/47003225/internet-connection-inside-docker-container-in-kubernetes/47008722#47008722">Internet connection inside Docker container in Kubernetes</a></p>

<p>Ok finally after lot of struggle I find the solution.<br>
So when ever K8s starts a pod it starts a sidecart container whose role is basically to provide network to pod containers.<br>
So while running docker build if I pass it's container ID as network then my intermediate contexts start getting internet connectivity via this container.

So changes looks something like this:</p>

<pre><code>docker build -t "some name" --network container:\$(docker ps | grep \$(hostname) | grep k8s_POD | cut -d\" \" -f1) -f infra/docker/Dockerfile .
</code></pre>

<p>Hope this helps. :D</p>
