Docker之jenkins环境搭建

1.持续集成概述

CI:持续集成。


image.png

CD:持续交付。


image.png

2.jenkins环境搭建与启动

jenkins的环境搭建步骤:
1.搜索jenkins:docker search jenkins
2.拉取jenkins镜像:docker pull jenkins/jenkins:lts
3.查看jenkins镜像:docker images
4.创建本地数据卷:
mkdir -p /var/jenkins_home/ #创建目录
chmod 777 /var/jenkins_home/ #修改权限目录
5.创建容器:docker run -id --name=jenkins -p 7070:8080 -v /var/jenkins_home/:/var/jenkins_home jenkins/jenkins:lts
其中命令详解:注意冒号后面的全部是固定值,不能改变,前面可以变更。
-d:容器后台运行
-p:端口映射
-v:数据卷挂载,绑定数据库
6.配置jenkins,访问网址:http://宿主机ip:7070/
7.界面进入jenkins,输入管理员密码:cat /var/jenkins_home/secrets/initialAdminPassword #获取管理员密码

[root@cs007 ~]#docker search jenkins 
[root@cs007 ~]# docker pull jenkins/jenkins:lts
lts: Pulling from jenkins/jenkins ...
1015a0aa0fa0: Pull complete 
Digest: sha256:092c78dbba52bf9cb207c592587e9377a7da2702cc201eb8e2daa9f278e0eb02
Status: Downloaded newer image for jenkins/jenkins:lts
docker.io/jenkins/jenkins:lts
[root@cs007 ~]# docker images
REPOSITORY                                    TAG                IMAGE ID       CREATED        SIZE
jenkins/jenkins                               lts                de181f8c70e8   34 hours ago   569MB
[root@ecs-429b ~]$>docker run -id --name jenkins -p 7070:8080 -v /var/jenkins_home/:/var/jenkins_home jenkins/jenkins:lts 
132e5cf78f6a5080ad4023d71bcbf6a9e61a5d1fd0cf653757754638c6bf4b7d
[root@ecs-429b ~]$>docker ps -a
CONTAINER ID   IMAGE                 COMMAND                  CREATED          STATUS          PORTS                                                  NAMES
132e5cf78f6a   jenkins/jenkins:lts   "/sbin/tini -- /usr/…"   29 seconds ago   Up 28 seconds   50000/tcp, 0.0.0.0:7070->8080/tcp, :::7070->8080/tcp   jenkins
[root@ecs-429b ~]$>cat /var/jenkins_home/secrets/initialAdminPassword
a778cdbb6b81448b963c3eb81ef183b9

提升技巧
1.容器的配置文件修改对应的端口号---修改完请重启容器
/var/lib/docker/containers/容器的id/hostconfig.json
docker start 容器id
2.docker logs 容器id #指令获取jenkins密码
jenkins密码获取执行命令-方式一:
docker logs 132e5cf78f6a
或者
2.cat /var/jenkins_node/secrets/initialAdminPassword#该指令也可以获取jenkins密码
jenkins密码获取执行命令-方式二:
[root@ecs-429b ~]$>cat /var/jenkins_home/secrets/initialAdminPassword
a778cdbb6b81448b963c3eb81ef183b9

3.jenkins下安装python相关资源

4.jenkins相关资源文档

jenkins官方文档:https://github.com/jenkinsci/docker/blob/master/README.md
https://www.jenkins.io/zh/doc/book/installing/

你可能感兴趣的:(Docker之jenkins环境搭建)