1.查看Jenkins LTS 版本
Jenkins官网:https://www.jenkins.io/zh/download/
2.拉取jenkins镜像
docker pull jenkins/jenkins:2.346.1
3.创建挂载数据卷
创建/home/software/jenkins/jenkins_home文件夹
mkdir /home/software/jenkins/jenkins_home
赋予/home/software/jenkins/jenkins_home/ 文件夹访问权限
chown -R 1000 /home/software/jenkins/jenkins_home/
chmod 777 /home/software/jenkins/jenkins_home/
赋予 /var/run/docker.sock文件访问权限
chmod 777 /var/run/docker.sock
4.配置并启动jenkins
docker run -d -m 2g -p 8600:8080 -p 50000:50000 \--restart=always \-v /home/software/jenkins/jenkins_home:/var/jenkins_home \-v /var/run/docker.sock:/var/run/docker.sock \-v /usr/bin/docker:/usr/bin/docker \--name jenkins \jenkins/jenkins:2.346.1
-d: 后台启动
-m: 设置内存大小(m-M,g-G)
-u: 使用管理员权限启动
–restar=always: 开机启动,失败也会一直重启
-p: 映射端口
-v: 挂载数据卷
/var/jenkins_home: jenkins挂载目录
/var/run/docker.sock: 外部docker挂载目录
/usr/bin/docker: 外部docker启动目录
–name: 容器名称
进入jenkens容器内部,查看docker是否挂载成功
docker exec -it jenkins /bin/bash
docker version
5.通过IP:8600启动jenkins并初始化
http://192.168.101.65:8600/
初始密码在日志文件中可查看,保存密码的目录:/var/jenkins_home/secrets/initiaAdminPassword
6.Jenkins安装插件
点击 Manage Jenkins(系统管理) -> Manage Plugins(插件管理)
- maven插件
- Publish Over SSH
- SSH插件
安装完插件,重启Jenkins