一、下载镜像

docker pull jenkinsci/jenkins

二、运行Jenkins容器

docker run --name myjenkins -d -p 8580:8080 -p 50000:50000 -v /mnt/docker/jenkins/jenkins_home:/var/jenkins_home jenkinsci/jenkins

三、 查看容器日志出现如下错误

[root@iZ2ze3zda3caeyx6pn7c5zZ jenkins]# docker logs -f d67e534e5af6102eb3d9d57633fcb616e77da80697ca0368caacfcd92e0a617a
touch: cannot touch '/var/jenkins_home/copy_reference_file.log': Permission denied
Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions?

需要修改下目录权限, 因为当映射本地数据卷时,/mnt/docker/jenkins/jenkins_home目录的拥有者为root用户,而容器中jenkins user的uid为1000
执行:

sudo chown -R : /mnt/docker/jenkins/jenkins_home

重启容器就可以了:

docker restart d67e534e5af6

四、Jenkins访问

1.查看jenkins启动日志,来获取初始密码

docker logs

*************************************************************
*************************************************************
*************************************************************
Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:
5973ab4bb61d48d1afa6930059d815b0
This may also be found at: /var/jenkins_home/secrets/initialAdminPassword
*************************************************************
*************************************************************
*************************************************************

2.访问地址
http://{ip地址}:8580

05-14 10:15