Docker实战2--使用docker搭建jenkins
jenkins安装
准备工作
1)搭建好docker环境的服务器一台。若无,可参考
《Docker实战1–linux安装docker环境》.
2)docker hub账号一枚。登录 https://hub.docker.com/ 注册即可
选择安装版本
访问网站:https://hub.docker.com/_/jenkins?tab=tags
登录dockerhub
[root@iZwz91xlsyfkpdi3c46mcdZ ~]# docker login -u 用户名 -p 密码
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
下载最新版本的docker镜像
[root@iZwz91xlsyfkpdi3c46mcdZ ~]# docker pull jenkins:latest
latest: Pulling from library/jenkins
55cbf04beb70: Downloading [====> ] 4.135MB/45.31MB
1607093a898c: Downloading [================================================> ] 10.48MB/10.74MB
9a8ea045c926: Downloading [============================> ] 2.444MB/4.336MB
d4eee24d4dac: Waiting
c58988e753d7: Waiting
794a04897db9: Waiting
70fcfa476f73: Waiting
0539c80a02be: Waiting
54fefc6dcf80: Waiting
911bc90e47a8: Waiting
...
查看下载好的镜像
[root@iZwz91xlsyfkpdi3c46mcdZ ~]# docker images
REPOSITORY TAG IMAGE ID
jenkins latest cd14cecfdb3a 2 years ago 696MB
...
创建挂载目录
[root@iZwz91xlsyfkpdi3c46mcdZ jenkins_home]# mkdir /home/jenkins/jenkins_home
启动jenkins
使用本地的8092,50092映射docker内部的8080,50000端口
[root@iZwz91xlsyfkpdi3c46mcdZ jenkins]# docker run -u root --rm -d -p 8092:8080 -p 50092:50000 -v /home/jenkins/jenkins_home:/var/jenkins_home jenkins:latest
75898a5705fb1d1da48f37443d5afcbb7351a0624cefa368e62c3daa93936159
查看镜像是否正常运行
[root@iZwz91xlsyfkpdi3c46mcdZ jenkins]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
75898a5705fb jenkins:latest "/bin/tini -- /usr/l…" 18 seconds ago Up 17 seconds 0.0.0.0:8092->8080/tcp, 0.0.0.0:50092->50000/tcp quirky_babbage
前端访问
访问地址:http://ip:8092
输入初始化密码
因为我们挂载到了/home/jenkins/jenkins_home,故通过以下命令可查看密码
[root@iZwz91xlsyfkpdi3c46mcdZ jenkins_home]# cat /home/jenkins/jenkins_home/secrets/initialAdminPassword
1839369060ad4fcf8668a00d2de17b89
选择安装方式,选择第二个,并跳过安装
jenkins默认使用国外的源,下载速度极慢,可进入jenkins后修改下载源
至此,docker安装完毕
更新源
进入jenkins主页,点击Manage Jenkins->Manage Plugins->Advanced
修改Update Site为http://updates.jenkins.io/update-center.json,之后需要下载的插件在Manage Plugins页面搜索并下载即可