【发布时间】:2018-07-26 17:11:07
【问题描述】:
我试图在我的个人电脑上构建一个简单的管道。我有詹金斯版本。 2.32.2 安装并运行。以下是我的管道的工作 dsl:
node {
stage('Github Checkout') {
checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '921fd840-1d71-4b06-bf5e-1c6f3141f669', url: 'git@github.com:justinsr20/tdd_django.git']]])
}
stage('Build container image') {
sh 'whoami'
}
stage('Build container image') {
sh 'pwd'
}
stage('Build container image') {
sh 'ls -l'
}
stage('Build container image') {
sh 'docker build -t jenkins/django:v1 -t jenkins/django:latest .'
}
}
我已经安装了 docker,并且我在 docker 组中有 jenkins 用户:
[root@localhost bin]# grep 'docker' /etc/group
docker:x:977:judd,jenkins
奇怪的是,当我尝试在上面定义的管道中运行 docker build 命令时,jenkins 给了我以下权限错误:
[workspace] Running shell script
+ whoami
jenkins
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Build container image)
[Pipeline] sh
[workspace] Running shell script
+ pwd
/var/lib/jenkins/jobs/tdd_django/workspace
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Build container image)
[Pipeline] sh
[workspace] Running shell script
+ ls -l
total 20
drwxr-xr-x. 3 jenkins jenkins 4096 Feb 10 11:11 django_app
-rw-r--r--. 1 jenkins jenkins 97 Feb 10 12:37 Dockerfile
-rw-r--r--. 1 jenkins jenkins 15 Feb 10 11:11 requirements.txt
-rw-r--r--. 1 jenkins jenkins 66 Feb 10 11:11 run_tests.sh
-rwxr-xr-x. 1 jenkins jenkins 69 Feb 10 12:48 script.sh
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Build container image)
[Pipeline] sh
[workspace] Running shell script
+ docker build -t jenkins/django:v1 -t jenkins/django:latest .
/var/lib/jenkins/jobs/tdd_django/workspace@tmp/durable-77854956/script.sh: line 2: /bin/docker: Permission denied
我的 docker 权限:
bash-4.3$ which docker
/bin/docker
bash-4.3$ ls -la /bin/docker
-rwxr-xr-x. 1 root root 12056512 Feb 8 16:44 /bin/docker
但是当我以 jenkins 用户身份打开 shell 会话时,我可以毫无问题地运行命令:
[root@localhost bin]# sudo su -s /bin/bash jenkins
bash-4.3$ cd /var/lib/jenkins/jobs/tdd_django/workspace
bash-4.3$ ls
django_app Dockerfile requirements.txt run_tests.sh script.sh
bash-4.3$ docker build -t jenkins/django:v1 -t jenkins/django:latest .
Sending build context to Docker daemon 76.8 kB
Step 1/3 : FROM python:2.7-onbuild
# Executing 3 build triggers...
Step 1/1 : COPY requirements.txt /usr/src/app/
---> Using cache
Step 1/1 : RUN pip install --no-cache-dir -r requirements.txt
---> Using cache
Step 1/1 : COPY . /usr/src/app
---> Using cache
---> fb9aa7078336
Step 2/3 : LABEL maintainer "CMI Industries"
---> Using cache
---> c1888038ffa2
Step 3/3 : RUN chmod +x /usr/src/app/run_tests.sh
---> Using cache
---> 8e61860e0567
Successfully built 8e61860e0567
任何帮助将不胜感激。
编辑更新:
所以如果 issues.jenkins-ci.org/browse/JENKINS-24338 是相关的,我需要修改 docker 服务的启动方式。我使用以下方式启动我的 docker 服务:
systemctl start docker
找到我使用的这个命令的配置文件:
[root@localhost system]# systemctl show --property=FragmentPath docker
FragmentPath=/usr/lib/systemd/system/docker.service
以及这个文件的内容:
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network.target firewalld.service
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
[Install]
WantedBy=multi-user.target
我不确定我需要如何修改此文件,以便“配置 docker 服务以将 'jenkins' 组所有权应用于套接字,而不是将 jenkins 用户添加到默认使用的 'docker' 组”,如问题中所述.jenkins-ci.org/browse/JENKINS-24338
【问题讨论】:
-
如果在 sudo 测试中使用 sh 而不是 bash 会怎样?
-
[root@localhost bin]# sudo su -s /bin/sh jenkins sh-4.3$ type docker docker is /bin/docker
-
你已经检查了所有明显的东西,它应该可以工作。我看到在目录列表中设置了一个 selinux 位,如果它没有被禁用,我会尝试下一个。
-
嘿 Nehal 我想你可能会对那篇文章有所了解。我只是注意确定如何为 Fedora 修改 /usr/lib/systemd/system/docker.service。正如最后一条评论为centos 提到的,但我在该文件中没有 SocketGroup 设置。我已经编辑了主帖