docker 搭建jenkins, 宿主机挂载路径uid,gid均正确却还报Permission denied,请考虑是否是selinux缘故
1)创建jenkins容器:docker run -d --name jenkins -p 8080:8080 -p 8081:8081 -v /var/jenkins_home:/var/jenkins_home jenkins(note:docker中jenkins的uid,gid默认都是1000,因此宿主机的路径必须也要设置成相同的权限)2)检查容器状态:dock
1)创建jenkins容器:
docker run -d --name jenkins -p 8080:8080 -p 50000:50000 -v /var/jenkins_home:/var/jenkins_home jenkins
(note:docker中jenkins的uid,gid默认都是1000,因此宿主机的路径必须也要设置成相同的权限)
2)检查容器状态:
docker ps -a
3)如果还是exit(1),docker logs <container id>提示permission denied的情况,请检查宿主机是否开启selinux:
宿主机切换jenkins用户,id命令查看到:
bash-4.2$ id
uid=1000(jenkins) gid=1000(jenkins) groups=1000(jenkins) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
而docker环境下id命令结果没有上面标红:
[root@localhost jenkins_home]# docker run -ti --rm --entrypoint="/bin/bash" jenkins -c "id"
uid=1000(jenkins) gid=1000(jenkins) groups=1000(jenkins)
宿主机下执行/usr/sbin/sestatus -v命令查看selinux状态:
[root@localhost jenkins_home]# /usr/sbin/sestatus -v
SELinux status: enabled
那么就可以判定selinux是打开的
4)那么处理方法有两种:
a.关闭selinux(网上搜一搜方法)
b.不关闭selinux的情况下,修改宿主机jenkins挂载目录的权限:
在宿主机执行ls -Z可以查看selinux信息,
[root@localhost jenkins_home]# ls -Za
drwxr-xr-x. jenkins jenkins system_u:object_r:var_t:s0 .
drwxr-xr-x. root root system_u:object_r:var_t:s0 ..
那么同样在docker环境下查看selinux信息,
[root@localhost jenkins_home]# docker run -ti --rm --entrypoint="/bin/bash" jenkins -c "cd /var/jenkins_home;ls -Zal"
total 20
drwxr-xr-x. 2 jenkins jenkins system_u:object_r:svirt_sandbox_file_t:s0 4096 Dec 8 07:57 .
drwxr-xr-x. 12 root root system_u:object_r:svirt_sandbox_file_t:s0:c365,c598 4096 Nov 8 21:55 ..
比较第三列确有差异。
接下来手动修改/var/jenkins_home目录的selinux权限即可:
[root@localhost jenkins_home]# chcon -R -t svirt_sandbox_file_t .
[root@localhost jenkins_home]# ls -aZl
total 84
drwxr-xr-x. 13 system_u:object_r:svirt_sandbox_file_t:s0 jenkins jenkins 4096 Dec 8 15:21 .
drwxr-xr-x. 21 system_u:object_r:var_t:s0 root root 4096 Dec 7 14:28 ..
5)重启jenkins
docker restart <container id>
或者删除旧的容器,新建:
docker rm <container id>
docker run -d --name jenkins -p 8080:8080 -p 50000:50000 -v /var/jenkins_home:/var/jenkins_home jenkins
更多推荐
所有评论(0)