如何使用jenkins docker容器挂载docker卷? [英] How to mount docker volume with jenkins docker container?

查看:345
本文介绍了如何使用jenkins docker容器挂载docker卷?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在容器中运行了jenkins,并在github上运行了项目源代码。

I have jenkins running inside container and project source code on github.

我需要在与jenkins相同的主机上运行容器中的项目,但不能作为docker-在码头工人中,我想将它们作为同级容器运行。

I need to run project in container on the same host as jenkins, but not as docker-in-docker, i want to run them as sibling containers.

我的管道如下所示:


  1. 从github提取源代码

  2. 构建项目图像

  3. 运行项目容器

我现在正在使用jenkins容器中主机的docker套接字:

What i do right now is using the docker socket of host from jenkins container:

/var/run/docker.sock:/var/run/docker.sock

当jenkins容器将带有/ var / jenkins_home / workspace / BRANCH_NAME的源代码的卷装入项目容器时,我遇到问题:

I have problem when jenkins container mount the volume with source code from /var/jenkins_home/workspace/BRANCH_NAME to project container:

volumes:
 - ./servers/identity/app:/srv/app

我正在项目容器中的空文件夹 / srv / app

i am getting empty folder "/srv/app" in project container

我的最佳猜测是docker尝试将其挂载m主机,而不是jenkins容器。

My best guess is that docker tries to mount it from host and not from the jenkins container.

所以问题是:如何显式设置从中装入卷的容器?

So the question is: how can i explicitly set the container from which i mount the volume?

推荐答案

在使用Jenkins docker容器运行另一个容器时,我遇到了同样的问题。

I got the same issue when using Jenkins docker container to run another container.

这不是推荐的方式,说明在此处。如果仍然需要使用此方法,那么这个问题就不成问题了。

This is not a recommended way, explanations goes here. If you still need to use this approach, then this problem is not a problem.

假设我们需要在Jenkins docker容器内运行另一个容器( ContainerA ), docker管道插件将使用-volumes -从安装到 Jenkins容器卷 ContainerA

Suppose, we need to run another container (ContainerA) inside Jenkins docker container, docker pipeline plugin will use --volumes-from to mount Jenkins container volume to ContainerA.

如果您尝试使用-volume -v Jenkins容器中的特定目录映射到 ContainerA ,您会遇到意外的情况。

If you trying to use --volume or -v to map specific directory in Jenkins container to ContainerA, you will got an unexpected behavior.

-卷 -v 会尝试将主机中的目录映射到 ContainerA ,而不是从 Jenkins容器内部的目录进行映射。如果在主机中找不到目录,那么您将在 ContainerA 中获得一个空目录。

That's because --volumes or -v would try to map directories in host to ContainerA, rather than mapping from directories inside Jenkins container. If the directories not found in host, then you will get an empty dir inside ContainerA.

简而言之,我们无法将容器A的特定目录映射到容器B,只能将容器A的整个卷安装到容器B,并且

In short, we can not map a specific directory from containerA to containerB, we could only mount the whole volumes from containerA to containerB, and volume alias is not supported.


  1. 如果您的Jenkins使用主机卷运行,则可以映射

  2. 否则,您可以访问新创建的容器内与 Jenkins容器相同位置的文件。

  1. If your Jenkins is running with host volume, you can map the host directories to the target container.
  2. Otherwise, you can access the files inside the newly created container with the same location as Jenkins container.

这篇关于如何使用jenkins docker容器挂载docker卷?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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