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

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

问题描述

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

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

浏览器.启动一个 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 守护进程套接字(通常为 /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

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

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