Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins Docker in Docker on GCP/Kubernetes

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

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.

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.

like image 203
eggsy84 Avatar asked Dec 08 '25 14:12

eggsy84


2 Answers

There are two ways of accessing docker daemon from a Kubernetes Pod.

  1. 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 /var/run/docker.sock). Now, you can install docker inside your container and access the docker daemon of the host machine.

  2. The second method is using Docker-in-Docker (DinD). In this method, you can use the concept of a sidecar container 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 DOCKER_HOST to tcp://localhost:2375. You can find the complete Pod specification and a lot more details on the differences between the two approaches on my blog article about DinD on Kubernetes

like image 118
Abhinav Das Avatar answered Dec 11 '25 03:12

Abhinav Das


I don't know if this is the recommended way but you could take a look at how the DEIS dockerbuilder component does this. DEIS is porting their PaaS to Kubernetes under the name DEIS Workflow. dockerbuilder is the module that allows DEIS clients to build Docker images in the cluster.

like image 24
bfallik Avatar answered Dec 11 '25 01:12

bfallik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!