与Jenkins Docker Plugin和Jenkins Docker Slaves混淆

所以我在某些方面感到惊喜,看到Jenkins Docker插件将Docker镜像“推送”到我的Docker主机金属中,但也令人困惑,因为我的构build发生在Docker主机金属上运行的Docker Slave容器中。 即使我的Jenkins大师在Docker容器中运行,而不是直接在金属上运行…

继这个受欢迎的jenkins大师/奴隶指南之后,我到达了Jenkinsbuild立在临时Docker容器中工作的地步。

这意味着,当我为Jenkins构build一些我的源代码软件组件/服务时,构build将在Jenkins从站中启动,这恰好是由Jenkins Docker插件启动的Docker容器。

Jenkins的工作空间在这个奴隶容器中,安装了Docker插件的Jenkins主,一旦构build完成,将处置这个奴隶容器。 看到我帮助解释的图表:

在这里输入图像说明

消化了这个图表后,一些重要的跟踪点:

  • Jenkins Master和Jenkins Slave在同一个Docker主机金属上运行,因为我刚刚处于运行此系统的开始阶段
  • 我正在使用Docker插件和SSH Slaves插件来完成此设置

所以在这个Docker Slave中,我的软件组件/服务构build工件被创build,例如,它可能是.dll或.war。 碰巧遇到这种情况,我的构build工件将成为Docker镜像。 为了清楚起见,我正在运行的Docker容器(Jenkins Slave)中构build一个Docker镜像。

我的困惑开始于我的期望,我应该不得不显式运行cmd推我的软件组件Docker镜像构build工件到Dockerregistry。 否则,当Jenkins构build作业完成时,Docker插件将closuresDocker容器从属,处理(rm)从属容器,并且将丢失该容器内的构build工件。

究竟发生了什么,为什么我感到惊喜,至less在短时间内,我正在开发并运行,是Docker镜像在docker主机上显示出来的。

我很惊讶,Docker插件会去这个水平的假设/帮助…我知道Docker插件允许您configuration一个Dockerregistry,并且您可以添加构build/发布到Docker Cloud,我假设云被视为图像的registry,也许也是运行这些图像的地方:

在这里输入图像说明

特别有趣的是,我没有使用Docker插件进行任何构build步骤,我只是使用Docker插件为构buildJenkinsconfiguration一个Slave容器。Item:

在这里输入图像说明

我唯一的构build步骤是我执行一个Shell脚本,是的,这个脚本碰巧最终build立一个Docker镜像,但Docker插件不知道这一点:

在这里输入图像说明

Docker插件加速了Docker从属容器,我configuration了Docker插件,并告诉它一个Docker主机(在我的情况下,我的金属)Cloud是Docker插件调用Docker主机和Docker从属镜像以用于该Docker主机/云:

在这里输入图像说明 我只是误解了一个Jenkins构build工作空间时Docker从属容器内部发生的隔离问题吗?

Docker插件只是默认使用唯一的Docker Cloud(我的Docker主机金属),我已经设置了所有任何Docker命令,我碰巧在Jenkins Docker slave容器中运行? (通过安装Docker-CE的方式,一个从属容器)

我的jenkins大师docker文件:

 #reference #https://engineering.riotgames.com/news/putting-jenkins-docker-container FROM jenkins:2.60.1 MAINTAINER Brian Ogden USER root #Timezone ENV TZ=America/Los_Angeles RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone # Prep Jenkins Directories RUN mkdir /var/log/jenkins RUN mkdir /var/cache/jenkins RUN chown -R jenkins:jenkins /var/log/jenkins RUN chown -R jenkins:jenkins /var/cache/jenkins # Copy in local config filesfiles COPY plugins.sh /usr/local/bin/plugins.sh RUN chmod +x /usr/local/bin/plugins.sh # Install default plugins # Set list of plugins to download / update in plugins.txt like this # pluginID:version # credentials:1.18 # maven-plugin:2.7.1 # ... # NOTE : Just set pluginID to download latest version of plugin. # NOTE : All plugins need to be listed as there is no transitive dependency resolution. COPY plugins.txt /tmp/plugins.txt RUN /usr/local/bin/plugins.sh /tmp/plugins.txt USER jenkins #give Jenkins a nice 8 GB memory pool and room to handle garbage collection #ENV JAVA_OPTS="-Xmx8192m" #give Jenkins a nice base pool of handlers and a cap #ENV JENKINS_OPTS="--handlerCountStartup=100 --handlerCountMax=300" ENV JENKINS_OPTS="--logfile=/var/log/jenkins/jenkins.log --webroot=/var/cache/jenkins/war" 

我使用docker-compose和Docker卷与我的Jenkins Master,我的docker-compose.yml:

 version: '2' services: data: build: data image: tsl.devops.jenkins.data.image container_name: tsl.devops.jenkins.data.container master: build: master image: tsl.devops.jenkins.master.image container_name: tsl.devops.jenkins.master.container volumes_from: - data ports: - "50000:50000" #network_mode: "host" nginx: build: nginx image: tsl.devops.jenkins.nginx.image container_name: tsl.devops.jenkins.nginx.container ports: - "80:80" links: - master:jenkins-master slavebasic: build: context: ./slaves dockerfile: basic/Dockerfile image: tsl.devops.jenkins.slave.basic.image container_name: tsl.devops.jenkins.slave.basic.container slavedotnetcore: build: context: ./slaves dockerfile: dotnetcore/Dockerfile image: tsl.devops.jenkins.slave.dotnetcore.image container_name: tsl.devops.jenkins.slave.dotnetcore.container 

我的Jenkins主卷 /驱动器Dockerfile:

 #reference #https://engineering.riotgames.com/news/docker-jenkins-data-persists FROM centos:7 MAINTAINER Brian Ogden #create the Jenkins user in this container RUN useradd -d "/var/jenkins_home" -u 1000 -m -s /bin/bash jenkins #NOTE: we set the UID here to the same one the Cloudbees Jenkins image uses #so we can match UIDs across containers, which is essential if you want #to preserve file permissions between the containers. We also use the same home directory and bash settings. #Jenkins log directory RUN mkdir -p /var/log/jenkins RUN chown -R jenkins:jenkins /var/log/jenkins #Docker volume magic VOLUME ["/var/log/jenkins", "/var/jenkins_home"] USER jenkins #just a little output reminder of the container's purpose CMD ["echo", "Data container for Jenkins"] 

我的奴隶 Dockerfile:

 FROM centos:7 MAINTAINER Brian Ogden #the USER will be root by default just explicitly #expressing it for better documentation USER root # Install Essentials RUN yum update -y && \ yum clean all ############################################# # Jenkins Slave setup ############################################# RUN yum install -y \ git \ wget \ openssh-server \ java-1.8.0-openjdk \ sudo \ make && \ yum clean all # gen dummy keys, centos doesn't autogen them like ubuntu does RUN /usr/bin/ssh-keygen -A # Set SSH Configuration to allow remote logins without /proc write access RUN sed -ri 's/^session\s+required\s+pam_loginuid.so$/session optional pam_loginuid.so/' /etc/pam.d/sshd # Create Jenkins User RUN useradd jenkins -m -s /bin/bash # Add public key for Jenkins login RUN mkdir /home/jenkins/.ssh COPY /files/id_rsa.pub /home/jenkins/.ssh/authorized_keys #setup permissions for the new folders and files RUN chown -R jenkins /home/jenkins RUN chgrp -R jenkins /home/jenkins RUN chmod 600 /home/jenkins/.ssh/authorized_keys RUN chmod 700 /home/jenkins/.ssh # Add the jenkins user to sudoers RUN echo "jenkins ALL=(ALL) ALL" >> etc/sudoers ############################################# ############################################# # Docker and Docker Compose Install ############################################# #install required packages RUN yum install -y \ yum-utils \ device-mapper-persistent-data \ lvm2 \ curl && \ yum clean all #add Docker CE stable repository RUN yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo #Update the yum package index. RUN yum makecache fast #install Docker CE RUN yum install -y docker-ce-17.06.0.ce-1.el7.centos #install Docker Compose 1.14.0 #download Docker Compose binary from github repo RUN curl -L https://github.com/docker/compose/releases/download/1.14.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose #Apply executable permissions to the binary RUN chmod +x /usr/local/bin/docker-compose ############################################# ############################################# # .NET Core SDK ############################################# RUN yum install -y \ libunwind \ libicu RUN curl -sSL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?linkid=848821 RUN mkdir -p /opt/dotnet && tar zxf dotnet.tar.gz -C /opt/dotnet RUN ln -s /opt/dotnet/dotnet /usr/local/bin #add Trade Service Nuget Server RUN mkdir -p /home/jenkins/.nuget/NuGet COPY /files/NuGet.Config /home/jenkins/.nuget/NuGet/NuGet.Config RUN chown -R jenkins /home/jenkins/.nuget RUN chgrp -R jenkins /home/jenkins/.nuget RUN chmod 600 /home/jenkins/.nuget/NuGet/NuGet.Config RUN chmod 700 /home/jenkins/.nuget/NuGet #speed up dotnet core builds ENV NUGET_XMLDOC_MODE skip ENV DOTNET_SKIP_FIRST_TIME_EXPERIENCE true ############################################# # Expose SSH port and run SSHD EXPOSE 22 #Technically, the Docker Plugin enforces this call when it starts containers by overriding the entry command. #I place this here because I want this build slave to run locally as it would if it was started in the build farm. CMD ["/usr/sbin/sshd","-D"] 

一个示例软件/组件 Dockerfile将在Jenkins Slave Docker容器中创build一个Docker图像构build工件:

 FROM centos:7 MAINTAINER Brian Ogden #Timezone ENV TZ=America/Los_Angeles RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone RUN yum update -y && \ yum clean all ############################################# # .NET Core SDK ############################################# RUN yum install -y \ libunwind \ libicu RUN curl -sSL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?linkid=848821 RUN mkdir -p /opt/dotnet && tar zxf dotnet.tar.gz -C /opt/dotnet RUN ln -s /opt/dotnet/dotnet /usr/local/bin #speed up dotnet core builds ENV NUGET_XMLDOC_MODE skip ENV DOTNET_SKIP_FIRST_TIME_EXPERIENCE true ############################################# ############################################# # .NET Sevrice setup ############################################# ARG ASPNETCORE_ENVIRONMENT # Copy our code from the "/src/MyWebApi/bin/Debug/netcoreapp1.1/publish" folder to the "/app" folder in our container WORKDIR /app COPY ./src/TSL.Security.Service/bin/Debug/netcoreapp1.1/publish . # Expose port 5000 for the Web API traffic ENV ASPNETCORE_URLS http://+:5000 ENV ASPNETCORE_ENVIRONMENT $ASPNETCORE_ENVIRONMENT EXPOSE 5000 # Run the dotnet application against a DLL from within the container # Don't forget to publish your application or this won't work ENTRYPOINT ["dotnet", "TSL.Security.Service.dll"] ############################################# 

  • jenkinsgithub拉请求build设者选错了提交
  • 我应该运行哪个Java版本的Jenkins?
  • 哈德森/jenkins在哪里以及如何储存数据?
  • jenkins奴隶失败握手在窗口
  • 为什么Jenkins用户没有权限访问Docker unix套接字?
  • jenkins发布ssh成功连接服务器,但失败的put文件
  • One Solution collect form web for “与Jenkins Docker Plugin和Jenkins Docker Slaves混淆”

    根据您的Docker插件configuration,您正在使用172.17.0.1作为Docker主机。 在从属或主容器中,这将是在主机上运行的Docker守护进程(Docker中没有Docker在这里发生)。 当你的Jenkins从站build立一个映像(不pipe从服务器是作为一个容器还是在主机上运行),它正在使用主机上的Docker,这就是你的映像在主机上显示的原因。

    值得注意的是,这些数据可能首先会被从机使用的Docker卷(根据Jenkins Dockefilehttps://github.com/jenkinsci/docker/blob/9f29488b77c2005bbbc5c936d47e697689f8ef6e/Dockerfile中默认是/var/jenkins_home )。 在你的情况下,这只是data服务的一个卷(尽pipe在Compose v2格式中,你可以定义一个命名卷,你不需要创build一个数据容器)。 从这里,你的代码和Dockerfile通过tcp://172.17.0.1:4243的API被发送到主机上的Docker构build上下文。

    服务器问题集锦,包括 Linux(Ubuntu, Centos,Debian等)和Windows Server服务器.