简体   繁体   中英

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM