<p>I'm using <a href="https://github.com/jenkinsci/kubernetes-plugin" rel="nofollow noreferrer">kubernetes-plugin</a> and I have some issue to build docker images on top of K8S pod:</p>

<p>I'm creating POD with:</p>

<pre><code>podTemplate(containers: [
    containerTemplate(
        name: 'docker-build',
        image: 'docker',
        command: 'cat',
        ttyEnabled: true
    )
],
volumes: [
    hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock')
])
{
    node(POD_LABEL) {
        stage("Checkout") {
            dir("${env.WORKSPACE}/code") {
                script {
                    // Checkout - Works
                }
            }
        }

        stage ('Build docker images') {
            container('docker-build') {
                dir("${env.WORKSPACE}/code") {
                    sh """
                    ./build-images
                    """
                }
            }
        }
    }
}
</code></pre>

<p>But it fails on the docker build step:</p>

<pre><code>Err:1 http://deb.debian.org/debian stretch InRelease
  Temporary failure resolving 'deb.debian.org'
Err:2 http://security.debian.org/debian-security stretch/updates InRelease
  Temporary failure resolving 'security.debian.org'
Err:3 http://deb.debian.org/debian stretch-updates InRelease
  Temporary failure resolving 'deb.debian.org'
Reading package lists...
[91mW: Failed to fetch http://deb.debian.org/debian/dists/stretch/InRelease  Temporary failure resolving 'deb.debian.org'
W: Failed to fetch http://security.debian.org/debian-security/dists/stretch/updates/InRelease  Temporary failure resolving 'security.debian.org'
W: Failed to fetch http://deb.debian.org/debian/dists/stretch-updates/InRelease  Temporary failure resolving 'deb.debian.org'
W: Some index files failed to download. They have been ignored, or old ones used instead.
[0mReading package lists...
Building dependency tree...
Reading state information...
[91mE: Unable to locate package libpam-dev
E: Unable to locate package libpcap0.8-dev
E: Couldn't find any package by glob 'libpcap0.8-dev'
E: Couldn't find any package by regex 'libpcap0.8-dev'
E: Unable to locate package libpq5[0m[91m
E: Unable to locate package libtins-dev
E: Unable to locate package openjdk-8-jdk-headless
E: Unable to locate package python3
</code></pre>

<p>When accessing the POD with <code>kubectl exec</code> and trying to build, it fails on the same error:</p>

<pre><code>docker build -t my_test .
</code></pre>

<p>When trying to build the same with <code>--network=host</code> <strong>it works</strong>:</p>

<pre><code>docker build --network=host -t my_test .
</code></pre>

<p>I'm trying to understand why it requires <code>--network=host</code> in order to work.</p>

<p>BTW - when I'm in the Jenkins slave pod and I'm trying to download any packages or access to the internet it all works just fine, it happens only when I'm trying to build docker image and trying to download packages during this process.</p>

<p>I suspect that the <code>docker build</code> is failing because of some network misconfiguration or maybe docker network is getting a bad state during this docker build on top of docker ..</p>

<p>So far I have tried:</p>

<ul>
<li>Create the pod with <code>hostNetwork: true</code> and it didn't help.</li>
<li>Create the pod with <code>privileged: true</code> and it didn't help.</li>
<li>Many other hacks to make the pod running on different network and it did't help as well.</li>
</ul>

<p>Please assist.</p>

EddieM
<p>The latest versions of the AWS EKS-optimized AMI disable the docker bridge network by default. To enable it, add the <code>bootstrap_extra_args</code> parameter to your worker group template. <a href="https://github.com/terraform-aws-modules/terraform-aws-eks/blob/a9753e8303cb2a0827a432cde96ddd0aee7aa931/docs/enable-docker-bridge-network.md" rel="nofollow noreferrer">Source</a>.</p>
