Docker + Jenkins
一、拉镜像
docker search jenkins
docker pull docker.io/jenkins
二、运行容器
docker run --name jenkins \
-p 7080:8080 -p 50000:50000 \
-v /etc/localtime:/etc/localtime \
-e TZ="Asia/Shanghai" \
-v /home/docker/jenkins/jenkins_home:/var/jenkins_home \
-v /home/docker/jenkins/settings:/var/settings \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(which docker):/usr/bin/docker -d jenkins
出现问题:容器运行不起来
docker logs -f jenkins 查看 Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions? touch: cannot touch '/var/jenkins_home/copy_reference_file.log': Permission denied
解决方法:
cd home/docker ll -a 显示: drwxr-xr-x 4 root root 42 Jul 26 22:19 jenkins
sudo chown -R 1000:1000 jenkins/
ll -a
显示:
drwxr-xr-x 4 localadmin localadmin 42 Jul 26 22:19 jenkins
然后运行容器;
为什么文件夹的归属用户Id必须是1000?
对于初次接触jenkins的我来说,确实挺郁闷的。为什么UID必须是1000?带着疑问我去查看了Docker中央仓库提供的Dockerfile,在这里面看到了如下的代码:
三、进入容器
docker exec -it jenkins /bin/bash
四、登录jenkins
访问 ip:7080(运行时候配置的)提示输入密码:
访问挂载路径下
/home/docker/jenkins/jenkins_home/secrets/initialAdminPassword
获取密码
531451edbe864731ad8139d09236a265
然后就是安装插件、创建用户等等