二丫讲梵 二丫讲梵
首页
  • 最佳实践
  • 迎刃而解
  • Nginx
  • Php
  • Zabbix
  • AWS
  • Prometheus
  • Grafana
  • CentOS
  • Systemd
  • Docker
  • Rancher
  • Ansible
  • Ldap
  • Gitlab
  • GitHub
  • Etcd
  • Consul
  • RabbitMQ
  • Kafka
  • MySql
  • MongoDB
  • OpenVPN
  • KVM
  • VMware
  • Other
  • ELK
  • K8S
  • LLM
  • Nexus
  • Jenkins
  • 随写编年
  • 家人物语
  • 追忆青春
  • 父亲的朋友圈
  • 电影音乐
  • 效率工具
  • 博客相关
  • Shell
  • 前端实践
  • Vue学习笔记
  • Golang学习笔记
  • Golang编程技巧
  • 学习周刊
  • Obsidian插件周刊
关于
友链
  • 本站索引

    • 分类
    • 标签
    • 归档
  • 本站页面

    • 导航
    • 打赏
  • 我的工具

    • 备忘录清单 (opens new window)
    • json2go (opens new window)
    • gopher (opens new window)
    • 微信MD编辑 (opens new window)
    • 国内镜像 (opens new window)
    • 出口IP查询 (opens new window)
    • 代码高亮工具 (opens new window)
  • 外站页面

    • 开往 (opens new window)
    • ldapdoc (opens new window)
    • HowToStartOpenSource (opens new window)
    • vdoing-template (opens new window)
GitHub (opens new window)

二丫讲梵

行者常至,为者常成
首页
  • 最佳实践
  • 迎刃而解
  • Nginx
  • Php
  • Zabbix
  • AWS
  • Prometheus
  • Grafana
  • CentOS
  • Systemd
  • Docker
  • Rancher
  • Ansible
  • Ldap
  • Gitlab
  • GitHub
  • Etcd
  • Consul
  • RabbitMQ
  • Kafka
  • MySql
  • MongoDB
  • OpenVPN
  • KVM
  • VMware
  • Other
  • ELK
  • K8S
  • LLM
  • Nexus
  • Jenkins
  • 随写编年
  • 家人物语
  • 追忆青春
  • 父亲的朋友圈
  • 电影音乐
  • 效率工具
  • 博客相关
  • Shell
  • 前端实践
  • Vue学习笔记
  • Golang学习笔记
  • Golang编程技巧
  • 学习周刊
  • Obsidian插件周刊
关于
友链
  • 本站索引

    • 分类
    • 标签
    • 归档
  • 本站页面

    • 导航
    • 打赏
  • 我的工具

    • 备忘录清单 (opens new window)
    • json2go (opens new window)
    • gopher (opens new window)
    • 微信MD编辑 (opens new window)
    • 国内镜像 (opens new window)
    • 出口IP查询 (opens new window)
    • 代码高亮工具 (opens new window)
  • 外站页面

    • 开往 (opens new window)
    • ldapdoc (opens new window)
    • HowToStartOpenSource (opens new window)
    • vdoing-template (opens new window)
GitHub (opens new window)
  • Nexus系列文章

  • Jenkins系列文章

    • Jenkins入门系列笔记汇总整理
    • 前言与介绍
    • Jenkins初始部署与简单配置
    • Jenkins各配置选项介绍
    • Jenkins中一个项目的构建
    • Jenkins配置项目构建的钉钉通知
    • Jenkins忘记管理员密码怎么办
    • Jenkins与gitlab的交互探微
    • Jenkins根目录详解
    • Jenkins插件之显示构建时间
    • Jenkins插件之批量修改配置
    • Jenkins配置简单构建邮件推送
    • Jenkins复杂邮件推送配置详解
    • Jenkins配置复杂构建邮件推送
    • Jenkins构建安卓项目之前的一些唠叨
    • Jenkins构建安卓项目配置
    • Jenkins与Gitlab分支的交互
    • Jenkins构建nodejs项目
    • 使用docker部署Jenkins及初始配置
      • 1,先下载 Jenkins 的镜像。
      • 2,查看镜像。
      • 3,将镜像启动成容器。
      • 4,查看启动的容器。
      • 5,初入 Jenkins。
      • 6,基础软件安装。
        • 1,maven。
        • 2,git。
        • 3,jdk。
      • 7,Jenkins 中的基础配置。
    • 配置gitlab提交代码Jenkins自动构建
    • Jenkins回滚方案探微
    • Jenkins角色控制(小黄锁)探微
    • Jenkins构建的应用配置问题解决探微
    • Jenkins构建中tag的应用
    • Jenkins插件之Ansicolor(神器)
    • 最基础核心的Jenkins功能部署一个java应用
    • Jenkins+sonar构建代码扫描
    • Jenkins+docker+gitlab将应用部署到docker
    • Jenkins参数化构建犀利插件Active-Choices-Plugin
    • 记一次将代码中参数外显到构建历史中的操作
    • Jenkins升级与迁移的经验分享
    • pipeline笔记之从一个简单的项目构建开始
    • Jenkinsfile声明式语法详解
    • 自动构建的原始配置以及pipeline中的用法
    • 多分支构建的实践与思考
    • 使用Jenkinsfile类前端项目的部署与回滚
    • 如何在Jenkinsfile中定义一个全局的时间戳变量
    • Jenkins中自由风格回滚方案的最佳实践
    • Jenkins中pipeline风格回滚方案的最佳实践
    • pipeline结合ansible剧本进行批量的部署与回滚配置
    • 最近配置安卓iOS打包本地化流程中一些值得记录的内容
    • pipeline中如何在environment环节声明一个含有通配符的变量
    • git-Parameter插件在pipeline共享库中的实践详解
    • jenkins作为ci检测代码是否合并的实践
    • 将Jenkins共享库的Jenkinsfile放到ci静态检测的实践
    • Jenkins的pipeline实践之GitSCM参数配置项详解
    • Jenkins中pipeline对接CMDB接口获取主机列表的发布实践
    • Jenkins有任务无法kill提示即将关闭
    • Jenkins基于Share Library共享库的最佳实践探索
    • Jenkins结合MySql Database插件的平台化实践思路
    • Jenkins-Groovy中三元表达式的用法
    • Jenkins-Groovy中Switch的高阶用法
    • Jenkins-pipeline之利用activity choice插件对接查询MySQL数据实现动态参数化的功能
    • CentOS通过yum快速安装Jenkins
    • Jenkins-pipeline语法之错误处理详解(文末有干货)
    • Jenkins常用插件汇总以及简单介绍
    • Jenkins所遇报错汇总及解决
    • Jenkins管理维护运维规范
  • ELK笔记

  • Kubernetes笔记

  • LLM专题

  • 系列专题
  • Jenkins系列文章
二丫讲梵
2021-06-16
目录

使用docker部署Jenkins及初始配置

文章发布较早,内容可能过时,阅读注意甄别。

注:本文章根据网上飞翔分享的文档整理。

关于 docker 的安装部署,这里暂先略掉。

# 1,先下载 Jenkins 的镜像。

[root@localhost ~]$docker pull jenkinsci/blueocean
Using default tag: latest
latest: Pulling from jenkinsci/blueocean
ff3a5c916c92: Pull complete
5de5f69f42d7: Pull complete
fd869c8b9b59: Pull complete
09b77ebbb585: Pull complete
edaab8c638eb: Pull complete
74718d164167: Pull complete
6d6dab0396d5: Pull complete
f6a4487e3af7: Pull complete
4b44a66deffd: Pull complete
925e68272890: Pull complete
428de9991230: Pull complete
f4b1af398075: Pull complete
425d68489478: Pull complete
e2f8bb400606: Pull complete
251d043c8226: Pull complete
9a6a8fe90c4f: Downloading [==============================================>    ]  62.19MB/66.73MB
9a6a8fe90c4f: Pull complete
Digest: sha256:df6669eab61f76cba7b51847ef24623f65902499925b4d5a2516d155dc95c0c5
Status: Downloaded newer image for jenkinsci/blueocean:latest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

# 2,查看镜像。

[root@localhost ~]$docker images
REPOSITORY           TAG             IMAGE ID            CREATED             SIZE
jenkinsci/blueocean  latest          52e299133c9c        20 hours ago        438MB
1
2
3

# 3,将镜像启动成容器。

docker run -d  \
--name jk -u root \
-p 9090:8080  \
-v /var/jenkins_home:/var/jenkins_home  \
jenkinsci/blueocean
1
2
3
4
5

说明:

  • 1,–name 是指定生成的容器名称。
  • 2,最好使用 root 启动,以免有权限问题而启动失败。
  • 3,-p 是端口的映射,冒号前边是宿主机的端口,冒号后边的是容器的端口。
  • 4,-v 将 Jenkins 容器的 Jenkins_home 映射到宿主机的目录中,实现数据持续化。

# 4,查看启动的容器。

[root@localhost ~]$docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                               NAMES
19e670dc09b0        jenkinsci/blueocean   "/sbin/tini -- /usr/…"   4 seconds ago       Up 3 seconds        50000/tcp, 0.0.0.0:9090->8080/tcp   jenkins
1
2
3

启动之后就可以直接通过宿主机 ip+映射的端口进行访问了。

# 5,初入 Jenkins。

注意刚进入之后会有一个坑。

image

这里看到指定了一个路径,去到 var 下去找,但是这个目录下并没有这个目录,可能这是镜像默认的一个路径,但是事实却并非如此。

那么我们就要用一下 find 大法了(其实在/var/lib/docker/volumes/c727610d35c19516dc279ffb9cc8ef68a3ff9e8ef4798a4e2730a1223f22d372/secrets/initialAdminPassword 之中。)。

image

这里是我之前起了几次容器才会有多个文件,根据时间判断是哪个就行了。

接下来去到容器当中看看。

[root@localhost mnt]$docker exec -it jk bash
bash-4.4#
bash-4.4# ls
bin  etc   lib	  mnt	root  sbin  sys  usr
dev  home  media  proc	run   srv   tmp  var
bash-4.4#
1
2
3
4
5
6

注意这里容器中使用apk命令来管理应用的安装配置,类似于系统中的yum命令。

先来查看一下 apk 命令的用法。

点击查看
bash-4.4# apk -h
apk-tools 2.8.2, compiled for x86_64.
usage: apk COMMAND [-h|--help] [-p|--root DIR]
           [-X|--repository REPO] [-q|--quiet]
           [-v|--verbose] [-i|--interactive]
           [-V|--version] [-f|--force]
           [--force-binary-stdout]
           [--force-broken-world]
           [--force-non-repository]
           [--force-old-apk] [--force-overwrite]
           [--force-refresh] [-U|--update-cache]
           [--progress] [--progress-fd FD]
           [--no-progress] [--purge]
           [--allow-untrusted] [--wait TIME]
           [--keys-dir KEYSDIR]
           [--repositories-file REPOFILE]
           [--no-network] [--no-cache]
           [--cache-dir CACHEDIR] [--arch ARCH]
           [--print-arch] [ARGS]...

The following commands are available:
  add       Add PACKAGEs to 'world' and install
            (or upgrade) them, while ensuring
            that all dependencies are met
  del       Remove PACKAGEs from 'world' and
            uninstall them
  fix       Repair package or upgrade it without
            modifying main dependencies
  update    Update repository indexes from all
            remote repositories
  info      Give detailed information about
            PACKAGEs or repositories
  search    Search package by PATTERNs or by
            indexed dependencies
  upgrade   Upgrade currently installed packages
            to match repositories
  cache     Download missing PACKAGEs to cache
            and/or delete unneeded files from
            cache
  version   Compare package versions (in
            installed database vs. available) or
            do tests on literal version strings
  index     Create repository index file from
            FILEs
  fetch     Download PACKAGEs from global
            repositories to a local directory
  audit     Audit the directories for changes
  verify    Verify package integrity and
            signature
  dot       Generate graphviz graphs
  policy    Show repository policy for packages
  stats     Show statistics about repositories
            and installations
  manifest  Show checksums of package contents

Global options:
  -h, --help              Show generic help or
                          applet specific help
  -p, --root DIR          Install packages to DIR
  -X, --repository REPO   Use packages from REPO
  -q, --quiet             Print less information
  -v, --verbose           Print more information
                          (can be doubled)
  -i, --interactive       Ask confirmation for
                          certain operations
  -V, --version           Print program version
                          and exit
  -f, --force             Enable selected
                          --force-* (deprecated)
  --force-binary-stdout   Continue even if binary
                          data is to be output
  --force-broken-world    Continue even if
                          'world' cannot be
                          satisfied
  --force-non-repository  Continue even if
                          packages may be lost on
                          reboot
  --force-old-apk         Continue even if
                          packages use
                          unsupported features
  --force-overwrite       Overwrite files in
                          other packages
  --force-refresh         Do not use cached files
                          (local or from proxy)
  -U, --update-cache      Update the repository
                          cache
  --progress              Show a progress bar
  --progress-fd FD        Write progress to fd
  --no-progress           Disable progress bar
                          even for TTYs
  --purge                 Delete also modified
                          configuration files
                          (pkg removal) and
                          uninstalled packages
                          from cache (cache
                          clean)
  --allow-untrusted       Install packages with
                          untrusted signature or
                          no signature
  --wait TIME             Wait for TIME seconds
                          to get an exclusive
                          repository lock before
                          failing
  --keys-dir KEYSDIR      Override directory of
                          trusted keys
  --repositories-file REPOFILE Override
                          repositories file
  --no-network            Do not use network
                          (cache is still used)
  --no-cache              Do not use any local
                          cache path
  --cache-dir CACHEDIR    Override cache
                          directory
  --arch ARCH             Use architecture with
                          --root
  --print-arch            Print default arch and
                          exit

This apk has coffee making abilities.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119

# 6,基础软件安装。

接下来操作一波安装一些常用的工具。

# 1,maven。

bash-4.4# apk add maven
OK: 402 MiB in 107 packages
bash-4.4# apk search ansible
ansible-2.4.1.0-r0
ansible-doc-2.4.1.0-r0
bash-4.4# apk add ansible
OK: 402 MiB in 107 packages
bash-4.4# apk add ansible-doc
OK: 402 MiB in 107 packages
1
2
3
4
5
6
7
8
9

接着查看一下这些工具在容器中是安在了什么地方。

bash-4.4# apk info -L maven
maven-3.5.2-r0 contains:
etc/mavenrc
usr/bin/mvnDebug
usr/bin/mvn
1
2
3
4
5

# 2,git。

bash-4.4# apk info -L git
usr/bin/git
usr/bin/git-upload-pack
usr/bin/git-receive-pack
usr/bin/git-upload-archive
usr/bin/git-shell
1
2
3
4
5
6

# 3,jdk。

bash-4.4# echo $JAVA_HOME
/usr/lib/jvm/java-1.8-openjdk
1
2

# 7,Jenkins 中的基础配置。

现在进行基础的配置,包括插件安装,环境变量的配置等。

插件有:

git
gitlab	可以配置与gitlab的连接。
Publish Over SSH	使用ssh的方式与remote服务器进行交互,之前一直使用命令代劳一切了,这次采用一下系统的插件。
docker
ansible
Monitoring	监控Jenkins所消耗的系统资源。
1
2
3
4
5
6

插件安装不做过多介绍。

我们来到系统设置–》全局工具配置页面。

依然是一些工具的配置。

刚才已经全部看过了,,现在配置如下。

image

image

上边都是一些基本工作,必须要做的,不然下边的事儿都免谈了。

接下来的操作则是完全利用 Jenkins 中的工具,把免秘钥工作的事儿给干了。我们来看下如何配置的。

首先在容器当中生成密钥对。

然后来到 Jenkins 中先将容器自己的私钥放进来。

在初始界面点击 Credentials 添加证书。

image

这个时候去容器中复制好刚生成的私钥,等下要用。

image

对圈起来的地方进行配置。然后点击 ok。就把 Jenkins 本机的私钥添加进去了,随后只要我们把 Jenkins 公钥放入其他地方(或者是服务器,或者是其他地方),就可以直接进行使用这个配置好的证书进行登陆了。

然后进入到系统配置,配置出容器中的 Jenkins 与远程服务器宿主机的信息,不要着急,这个地方的配置,会在等会儿用得到。

image

以上简单表述了一下 Jenkins 通过 docker 部署之后的一些简单配置过程。接下来也会开启 docker 时代,都以 docker 为基准进行更多功能的配置以及扩展。

就像日新月异的技术一样的,我们自己所掌握的,也应该是日日新的。

微信 支付宝
#jenkins#docker
上次更新: 2024/07/04, 22:40:37
Jenkins构建nodejs项目
配置gitlab提交代码Jenkins自动构建

← Jenkins构建nodejs项目 配置gitlab提交代码Jenkins自动构建→

最近更新
01
学习周刊-总第211期-2025年第20周
05-15
02
记录二五年五一之短暂回归家庭
05-09
03
学习周刊-总第210期-2025年第19周
05-09
更多文章>
Theme by Vdoing | Copyright © 2017-2025 | 点击查看十年之约 | 浙ICP备18057030号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式