Fix Docker in docker network issue in Kubernetes
Write down my experience to resolve a Docker in Docker network issue when doing docker build in Kubernetes
Problem
After writing about my approach to do fast docker build in Kubernetes in this article, I want to build some complex docker images.
A problem hit me hard that I could not download content from “some” places when building the image.
For example, if the Dockerfile has this line, it works well.
RUN curl -L "https://google.com"
But this line cause the “docker build” command stuck and eventually fail.
RUN curl -L -O " https://download.jetbrains.com/python/pycharm-community-2019.2.1.tar.gz"
The error could happen not only in curl command, but also in things like “pip” which download something from external.
Reproduce the scenario
It is a complex setup when doing docker build in Kubernetes. From outside-in we have the host machine, a Pod based on host Docker daemon, 2 containers in the Pod. Inside the pod we have dind container to provide dind Docker daemon, a docker container to run “docker build” command, and finally one container running on dind daemon to run the actual commands from Dockerfile.