Jenkins Docker在GCP/Kubernetes上的Docker中 [英] Jenkins Docker in Docker on GCP/Kubernetes

查看:133
本文介绍了Jenkins Docker在GCP/Kubernetes上的Docker中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在从加载到Kubernetes的容器中启动'docker build'命令的推荐方法?

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

IE.从社区映像启动一个Jenkins容器,然后确保在该容器中安装了docker,以便您可以发出"docker build"命令.

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.

我已经阅读了各种方法,例如DIND(Docker中的Docker)容器以及在Jenkins容器和DIND容器之间运行链接.当然,使用Kubernetes会有所不同.

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.

推荐答案

有两种方法可以从Kubernetes Pod访问docker守护进程.

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

  1. 您可以在容器内公开运行在主机上的docker守护程序(这是kubernetes用于旋转容器的docker守护程序).为此,您需要修改Pod规范以为docker守护进程套接字添加hostPath(通常为/var/run/docker.sock).现在,您可以在容器中安装docker并访问主机的docker守护程序.

  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.

第二种方法是使用Docker-in-Docker(DinD).在这种方法中,您可以使用 sidecar容器的概念在docker守护进程中运行docker.必须将pod中的主容器配置为与sidecar容器中的docker守护进程进行对话.您可以通过将环境变量DOCKER_HOST设置为tcp://localhost:2375来执行此操作.您可以在有关Kubernetes上DinD的博客文章

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

这篇关于Jenkins Docker在GCP/Kubernetes上的Docker中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆