How to manage jenkins based on docker


  今天我们来着重介绍一下如何基于docker环境来安装jenkins。

Installation

[root@xtwj69 ~]# mkdir -p /data/jenkins
[root@xtwj69 ~]# ll /data/jenkins
total 0
drwxr-xr-x. 2 root root  6 Dec 16 10:50 .
drwxr-xr-x. 3 root root 21 Dec 16 10:50 ..
[root@xtwj69 ~]# docker run -d --restart always --name jenkins -p 8080:8080 -p 50000:50000 -u root  -v /data/jenkins:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock jenkinsci/blueocean:1.21.0
922c61f710d435762b912880125fcdbf0c0f4ce87da053b367a3ba13f95a943c
[root@xtwj69 ~]# docker ps -a
CONTAINER ID        IMAGE                        COMMAND                  CREATED             STATUS              PORTS                                              NAMES
922c61f710d4        jenkinsci/blueocean:1.21.0   "/sbin/tini -- /usr/…"   31 seconds ago      Up 29 seconds       0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp   jenkins
[root@xtwj69 ~]# firewall-cmd --zone=public --add-port=8080/tcp --permanent
success
[root@xtwj69 ~]# firewall-cmd --zone=public --add-port=50000/tcp --permanent
success
[root@xtwj69 ~]# firewall-cmd --reload
success
[root@xtwj69 ~]# firewall-cmd --zone=public --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0
  sources: 
  services: dhcpv6-client ssh
  ports: 8080/tcp 50000/tcp
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
	
[root@xtwj69 ~]#

Configuration

打开浏览器,输入http://192.168.3.69:8080/即可打开jenkins初始化页面。

Please wait while Jenkins is getting ready to work …
Your browser will reload automatically when Jenkins is ready.
解法方法: 进入宿主机/data/jenkins/目录,编辑文件hudson.model.UpdateCenter.xml,

[root@xtwj69 ~]# ll /data/jenkins/
total 72
drwxr-xr-x.  15 root root  4096 Dec 16 14:24 .
drwxr-xr-x.   3 root root    21 Dec 16 10:50 ..
drwxr-xr-x.   3 root root    17 Dec 16 14:17 .cache
-rw-r--r--.   1 root root  1666 Dec 16 14:24 config.xml
-rw-r--r--.   1 root root  4025 Dec 16 14:21 copy_reference_file.log
drwxr-xr-x.   3 root root    20 Dec 16 14:17 .groovy
-rw-r--r--.   1 root root   156 Dec 16 14:21 hudson.model.UpdateCenter.xml
-rw-r--r--.   1 root root   370 Dec 16 14:17 hudson.plugins.git.GitTool.xml
-rw-------.   1 root root  1712 Dec 16 14:17 identity.key.enc
drwxr-xr-x.   3 root root    19 Dec 16 14:16 .java
-rw-r--r--.   1 root root  1179 Dec 16 14:27 jenkins.install.InstallUtil.installingPlugins
-rw-r--r--.   1 root root     7 Dec 16 14:17 jenkins.install.UpgradeWizard.state
-rw-r--r--.   1 root root   171 Dec 16 14:17 jenkins.telemetry.Correlator.xml
drwxr-xr-x.   2 root root     6 Dec 16 14:16 jobs
-rw-r--r--.   1 root root     0 Dec 16 14:22 .lastStarted
drwxr-xr-x.   4 root root    37 Dec 16 14:17 logs
-rw-r--r--.   1 root root   907 Dec 16 14:21 nodeMonitors.xml
drwxr-xr-x.   2 root root     6 Dec 16 14:17 nodes
drwxr-xr-x. 101 root root 16384 Dec 16 14:26 plugins
-rw-r--r--.   1 root root   129 Dec 16 14:21 queue.xml.bak
-rw-r--r--.   1 root root    64 Dec 16 14:16 secret.key
-rw-r--r--.   1 root root     0 Dec 16 14:16 secret.key.not-so-secret
drwx------.   4 root root   265 Dec 16 14:17 secrets
drwxr-xr-x.   2 root root   100 Dec 16 14:18 updates
drwxr-xr-x.   2 root root    24 Dec 16 14:17 userContent
drwxr-xr-x.   3 root root    56 Dec 16 14:17 users
drwxr-xr-x.  11 root root  4096 Dec 16 14:16 war
drwxr-xr-x.   2 root root     6 Dec 16 14:17 workflow-libs
[root@xtwj69 ~]# cat /data/jenkins/hudson.model.UpdateCenter.xml 
<?xml version='1.1' encoding='UTF-8'?>
<sites>
  <site>
    <id>default</id>
    <url>https://updates.jenkins.io/update-center.json</url>
  </site>
</sites>
[root@xtwj69 ~]# 

http://updates.jenkins-ci.org/update-center.json 修改成 http://mirror.xmission.com/jenkins/updates/update-center.json,然后重启docker容器。

在这里插入图片描述

这个时候,系统提示输入密码。我们需要进入容器中,将密码找出来。

[root@xtwj69 ~]# docker exec -it jenkins /bin/bash
root@6e5ca7b41e5c:/# ls -la /var/jenkins_home/secrets/initialAdminPassword
-rw-r-----. 1 root root 33 Dec 16 03:05 /var/jenkins_home/secrets/initialAdminPassword
root@6e5ca7b41e5c:/# cat /var/jenkins_home/secrets/initialAdminPassword
314ec2c188db456cabc0ec96878ebf89
root@6e5ca7b41e5c:/# exit
exit
[root@xtwj69 ~]#

我们看到,密码是314ec2c188db456cabc0ec96878ebf89,在浏览器页面中输入该密码即可进行后续配置。

在这里插入图片描述

[root@xtwj69 jenkins]# docker exec -it jenkins /bin/bash 
bash-4.4# mvn -v
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /var/jenkins_home/apache-maven-3.6.3
Java version: 1.8.0_212, vendor: IcedTea, runtime: /usr/lib/jvm/java-1.8-openjdk/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-1062.4.3.el7.x86_64", arch: "amd64", family: "unix"
bash-4.4#
bash-4.4# cat .bashrc 
export M2_HOME=/var/jenkins_home/apache-maven-3.6.3
export PATH=$PATH:$M2_HOME/bin
bash-4.4#

参考文献

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qwfys200

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值