创建目录
root@debian1:/mydata# mkdir /mydata/jenkins_home -pn
下载jenkins镜像
root@debian1:/mydata# docker pull jenkins
检查镜像
root@debian1:/mydata# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
31758056d8e2 3 hours ago 11.6MB
jenkins latest 0b4d4d677a26 4 days ago 681MB
marksugar/alpine latest 07a4ff4374e1 10 months ago 11.6MB
启动jenkins
root@debian1:/mydata# docker run --name myjenkins -p 8000:8080 -v $PWD/jenkins:/var/jenkins_home -t jenkins
touch:cannottouch‘/var/jenkins_home/copy_reference_file.log’:Permissiondenied
Cannotwriteto/var/jenkins_home/copy_reference_file.log.Wrongvolumepermissions?
错误处理
查看容器用户
root@debian1:/mydata# docker run -ti --rm --entrypoint="/bin/bash" jenkins -c "whoami && id"
jenkins
uid=1000(jenkins) gid=1000(jenkins) groups=1000(jenkins)
查看容器目录权限
root@debian1:/mydata#docker run -ti --rm --entrypoint="/bin/bash" jenkins -c "ls -la /var/jenkins_home"
total 20
drwxr-xr-x 2 jenkins jenkins 4096 Nov 22 07:43 .
drwxr-xr-x 26 root root 4096 Nov 8 21:55 ..
-rw-r--r-- 1 jenkins jenkins 220 Nov 12 2014 .bash_logout
-rw-r--r-- 1 jenkins jenkins 3515 Nov 12 2014 .bashrc
-rw-r--r-- 1 jenkins jenkins 675 Nov 12 2014 .profile
查看本地授权
root@debian1:/mydata/jenkins_home# ls -l
总用量 4
drxr-xr-x 16 root root 4096 6月 28 07:35 jenkins
更改授权
root@debian1:/mydata/jenkins_home# chown -R 1000 ./
再次启动
root@debian1:/mydata/jenkins_home# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8c221f324db2 jenkins "/bin/tini -- /usr..." About an hour ago Up About an hour 50000/tcp, 0.0.0.0:8000->8080/tcp myjenkins
a619127a44fa 31758056d8e2 "/bin/sh -c 'addgr..." 3 hours ago Exited (137) About an hour ago naughty_ritchie
root@debian1:/mydata/jenkins_home# docker start 8c221f324db2
访问测试
安装jenkins
本地访问jenkins
浏览器打开http://127.0.0.1:8000
登陆密码在/var/jenkins_home/secrets/initialAdminPassword查找
插件安装,这里选择了默认的Install plugins the Jenkins community finds most useful.安装。
懂的同学可以选择自己选择插件安装
解决“Getting Started”卡死问题
root@debian1:/mydata# cd jenkins/updates/
root@debian1:/mydata# vim default.json
将"http://www.google.com/",修改为"connectionCheckUrl":"http://www.baidu.com/",
重启服务,Ok!