搜索jenkins,查找自己想安装的jenkins
[root@xxxxx redis]# docker search jenkins
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
jenkins Official Jenkins Docker image 5195 [OK]
jenkins/jenkins The leading open source automation server 2543
jenkinsci/blueocean https://jenkins.io/projects/blueocean 622
jenkinsci/jenkins Jenkins Continuous Integration and Delivery … 389
jenkins/jnlp-slave a Jenkins agent which can connect to Jenkins… 144 [OK]
jenkinsci/jnlp-slave A Jenkins slave using JNLP to establish conn… 132 [OK]
jenkinsci/slave Base Jenkins slave docker image 67 [OK]
jenkins/slave base image for a Jenkins Agent, which includ… 47 [OK]
jenkinsci/ssh-slave A Jenkins SSH Slave docker image 44 [OK]
jenkins/ssh-slave A Jenkins slave using SSH to establish conne… 37 [OK]
cloudbees/jenkins-enterprise CloudBees Jenkins Enterprise (Rolling releas… 34 [OK]
bitnami/jenkins Bitnami Docker Image for Jenkins 33 [OK]
h1kkan/jenkins-docker 🤖 Extended Jenkins docker image, bundled wi… 29
xmartlabs/jenkins-android Jenkins image for Android development. 28 [OK]
openshift/jenkins-2-centos7 A Centos7 based Jenkins v2.x image for use w… 23
cloudbees/jenkins-operations-center CloudBees Jenkins Operation Center (Rolling … 14 [OK]
vfarcic/jenkins-swarm-agent Jenkins agent based on the Swarm plugin 8 [OK]
openshift/jenkins-slave-base-centos7 A Jenkins slave base image. DEPRECATED: see … 7
trion/jenkins-docker-client Jenkins CI server with docker client 6 [OK]
publicisworldwide/jenkins-slave Jenkins Slave based on Oracle Linux 5 [OK]
openshift/jenkins-1-centos7 DEPRECATED: A Centos7 based Jenkins v1.x ima… 4
ansibleplaybookbundle/jenkins-apb An APB which deploys Jenkins CI 1 [OK]
amazeeio/jenkins-slave A jenkins slave that connects to a master vi… 0 [OK]
jameseckersall/jenkins docker-jenkins (based on openshift jenkins 2… 0 [OK]
mashape/jenkins Just a jenkins image with the AWS cli added … 0 [OK]
使用docker pull 自己安装的jenkins,也可以在https://hub.docker.com/ 查看版本
[root@xxxxx redis]# docker pull jenkins/jenkins:2.60.3
等待下载完成,使用docker images,查看镜像版本
[root@xxxxx ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
redis latest fad0ee7e917a 6 days ago 105MB
jenkins/jenkins 2.60.3 c7d3b6093b29 3 years ago 811MB
创建宿主机的挂载目录,并赋权限
[root@xxxxx redis]# mkdir -p /data/jenkins_home/
[root@xxxxx redis]# chown -R 1000:1000 /data/jenkins_home/
启动并创建jenkins
[root@xxxxx redis]# docker run -d --name jenkins -p 8040:8080 -p 50000:50000 -v /data/jenkins_home:/var/jenkins_home -v /etc/localtime:/etc/localtime jenkins/jenkins:2.60.3
-d 后台运行镜像
-p 8040:8080 将镜像的8080端口映射到服务器的8040端口。
-p 50000:50000 将镜像的50000端口映射到服务器的50000端口
-v /data/jenkins_home:/var/jenkins_home /var/jenkins_home目录为容器jenkins工作目录,我们将硬盘上的一个目录挂载到这个位置,方便后续更新镜像后继续使用原来的工作目录。这里我们设置的就是上面我们创建的 /data/jenkins_home目录
-v /etc/localtime:/etc/localtime让容器使用和服务器同样的时间设置。
--name jenkins 给容器起一个别名
查看docker 镜像运行情况
[root@xxxxx /]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cbbcb8f77790 jenkins/jenkins:2.60.3 "/bin/tini -- /usr/l…" 15 hours ago Up 15 hours 0.0.0.0:50000->50000/tcp, 0.0.0.0:8040->8080/tcp jenkins
在浏览器上输入http://ip:8040 访问到jenkins
[root@xxxxx~]# docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword
f8b697107b114b0b8ae6779affab4529
输入密码后,点击继续
安装插件
会出现 No such plugin: cloudbees-folder;解决方法
到这个http://mirrors.jenkins.io/war/latest/网站去下载jenkins.war ,上传到服务器,并使用命令上传到jenkins容器中,并重启jenkins
[root@xxxxx jenkins_home]# docker cp /存放jenkins.war文件的目录/jenkins.war jenkins:/usr/share/jenkins/
[root@xxxxx jenkins_home]# docker restart jenkins
再次访问jenkins,http://ip:8040,登录进去,即可。如没有设置获取忘记用户名和密码,使用http://ip:8040/restart,在系统管理——安全——用户管理中设置用户名和密码
设置好后既可以,登录进去,然后去下载安装插件接口。
至此docker 下安装jenkins完成