Jenkins Docker in Docker on GCP/Kubernetes

ε祈祈猫儿з 提交于 2021-02-07 09:58:29

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/37647251/jenkins-docker-in-docker-on-gcp-kubernetes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!