<p>I have a Kubernetes pod based on jenkins/slave container to which I mount docker socket and docker binary file with necessary kernel module in privileged mode. Inside that pod I build Docker image basing on which I run docker container. Inside that container I don't have Internet connection at all because pod container uses flannel network (198.x.x.x) and that container uses bridged docker network (172.x.x.x) which is not available inside pod container. How can I make Internet to be available inside the second container which is being created inside Kubernetes pod container? Using Docker API in Jenkins pipeline is not a solution for me as long as it limits output of error logs and I can not commit changes made in the second container because of immediate removing of that container after build.</p>

<p>Not sure if this article will help you with this issue, <a href="https://radu-matei.com/blog/kubernetes-jenkins-azure/#configuring-jenkins-to-dinamically-spawn-agents-docker-containers-for-builds" rel="nofollow noreferrer">JENKINS DECLARATIVE PIPELINES WITH KUBERNETES</a> . This article shows a full stack on how to setup Jenkins in Kubernetes and also involves idea about Docker in Docker.</p>

<p>Based on my thought, we could mark as pod container as <code>container1</code> and container in pod as <code>container2</code>.</p>

<p>I think <code>container1</code> and <code>container2</code> should locate in the same host and shared the same docker engine. So flannel network with docker network should setup together.</p>

<p>As my idea, network flow for <code>container2</code> should be from <code>container2</code> -> <code>docker0</code> -> <code>host</code>, should be not with <code>container1</code>.</p>

<p>Just let me know if this should be reasonable, or we could discuss together, I think this question is very interesting.</p>
