在Jenkins从属服务器上发布docker命令 [英] Issue docker commands on Jenkins slave

查看:296
本文介绍了在Jenkins从属服务器上发布docker命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行在Windows Server 2016上的Jenkins主服务器.我需要能够运行linux容器来运行一些自动化的e2e测试.出于某些原因,我无法在此计算机上启用hyper-v.这使我无法在我的Jenkins主服务器上安装lcow和docker

I have a Jenkins master running on Windows Server 2016. I need to be able to run linux containers to run some automated e2e tests. For reasons I won't get into, I cannot enable hyper-v on this machine. This is preventing me from installing lcow and docker on my Jenkins master

我要做的是在virtualbox中安装Ubuntu 18.04 VM,并在那里安装了docker.我已使用ssh将VM配置为Jenkins从机,并以jenkins用户身份登录.我已经为此用户设置并配置了所有内容,使其能够在不使用sudo的情况下运行docker命令.如果我以jenkins用户的身份手动进入服务器,则可以运行docker命令,而不会出现问题.一切都按您期望的方式工作.

What I've done instead is setup a Ubuntu 18.04 VM in virtualbox and installed docker there. I've configured the VM as a Jenkins slave using ssh to login as the jenkins user. I've setup and configured everything for this user to be able to run docker commands without using sudo. If I manually ssh into the server as the jenkins user I can run docker commands without an issue. Everything works the way you would expect.

然后,我设置了一个测试版本,以检查一切是否正常运行.问题是,当我尝试使用Execute Shell构建步骤运行docker命令时,出现了docker: not found错误.据我所知,该构建正在以正确的用户身份运行.我在构建步骤中添加了who -u,这样我就可以检查构建以哪个用户运行.

I've then setup a test build to check that everything was working correctly. The problem is that when I try to run docker commands using the Execute Shell build step I'm getting a docker: not found error. From what I can tell, the build is running as the correct user. I added who -u to the build step so I could check which user the build was running as.

这是我构建的输出:

[TEST - e2e - TEST] $ /bin/sh -xe /tmp/jenkins16952572249375249520.sh
+ who -u
jenkins  pts/0        2018-08-10 16:43   .         10072 (10.0.2.2)
+ docker run hello-world
/tmp/jenkins16952572249375249520.sh: 3: /tmp/jenkins16952572249375249520.sh: docker: not found

正如我提到的,jenkins用户已添加到docker组,而Docker已添加到$PATH(/snap/bin/):

As I mentioned, the jenkins user has been added to the docker group and Docker has been added to $PATH (/snap/bin/):

jenkins@jenkins-docker-slave:~$ which docker
/snap/bin/docker
jenkins@jenkins-docker-slave:~$ $PATH
-bash:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin: No such file or directory
jenkins@jenkins-docker-slave:~$ who -u
jenkins  pts/0        2018-08-10 16:43   .         10072 (10.0.2.2)
jenkins@jenkins-docker-slave:~$ cat /etc/group | grep docker
docker:x:1001:qctesting,jenkins

如您在此片段中所见,我可以通过以jenkins用户身份登录服务器来成功运行docker命令:

As you can see by this snippet I can successfully run docker commands by logging into the server as the jenkins user:

jenkins@jenkins-docker-slave:~$ docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
 3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

我还已经在slaves节点属性中配置了docker的路径,因为我认为它可以解决我的问题.如您所见,我同时列出了git和docker. Git命令运行正常.只是docker命令给我带来了问题.我试过/snap/bin/snap/bin/docker都没有运气.

I have also configured the path to docker in the slaves node properties as I thought it would fix my issue. As you can see I have both git and docker listed. Git commands are working just fine. It is only the docker commands that are giving me problems. I have tried both /snap/bin and /snap/bin/docker with no luck.

我正在尝试构建一个詹金斯工作,该工作将克隆git repo,使用docker-compose旋转我需要的容器,并在构建时传入一些构建参数,并针对任何环境运行我的e2e测试(例如,分期,制作等).我只是无法让詹金斯奴隶来运行docker命令.我想念什么?如何让从属识别出docker已经安装在系统上,并且用户具有执行这些命令的正确权限.

I am trying to build a jenkins job that will clone a git repo, spin up the containers I need using docker-compose and some build parameters I pass in at build time, and run my e2e tests against any environment (qa, staging, production, etc.). I just can't get the jenkins slave to run the docker commands. What am I missing? How can I get the slave to recognize that docker is already installed on the system and the user has the correct permissions to execute those commands.

注意::我不是要在docker中运行docker.我在jenkins从属服务器上运行docker命令时发现的几乎所有问题/文档都描述了如何通过在docker容器中运行从属服务器并将docker客户端安装在从属容器中来解决此问题.那不是我要完成的.我正在尝试从jenkins主服务器切换到已经安装了docker的jenkins从服务器,并以jenkins用户的身份在该服务器上运行docker命令.

NOTE: I am NOT trying to run docker in docker. Practically all questions/documentation I've found on running docker commands on a jenkins slave describe how to solve this issue by running the slave in a docker container and installing the docker client in the slave container. That is not what I'm trying to accomplish. I am trying to ssh from a jenkins master into a jenkins slave that already has docker installed and run docker commands on that server as the jenkins user.

推荐答案

由于

I finally figured this out thanks to the answer for this question. After reading that answer I realized I had installed the wrong version of docker on Ubuntu. I removed the previous installation and installed the correct docker package using sudo curl -sSL https://get.docker.com/ | sh. I then restarted my jenkins slave and everything started working.

这篇关于在Jenkins从属服务器上发布docker命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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