1.目标
在docker环境下安装Jenkins,并实现流水线的初步学习。
2. 前置条件
3. 具体步骤
3.1 镜像拉取
? ~ docker pull jenkins/jenkins
Using default tag: latest
latest: Pulling from jenkins/jenkins
0e29546d541c: Pull complete
a881d3e39b57: Pull complete
d424caad5b90: Pull complete
469ee726cc8f: Pull complete
f5eff683d188: Pull complete
955c78102a93: Pull complete
1e670fe34dae: Pull complete
30a5b207ad53: Pull complete
3c421004e233: Pull complete
e2729810a28a: Pull complete
4c14906574b5: Pull complete
8d6f1717fa64: Pull complete
a43947c0b965: Pull complete
0dfe4ad317f0: Pull complete
51f8f56f3e20: Pull complete
3944cb7b63c3: Pull complete
f3ebba26875d: Pull complete
Digest: sha256:0c31a58707a69449d2db06a31dc76b6bdf7f690d2664406104185eac27d0d54b
Status: Downloaded newer image for jenkins/jenkins:latest
docker.io/jenkins/jenkins:latest
? ~ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
jenkins/jenkins latest 1c520775844c 45 hours ago 442MB
3.2 vloumes
mkdir -p /var/jenkins_mount
chmod 777 /var/jenkins_mount
3.3 创建并启动Jenkins容器
- -d 后台运行镜像
- -p 10240:8080 将镜像的8080端口映射到服务器的10240端口。
- -p 10241:50000 将镜像的50000端口映射到服务器的10241端口
- -v /var/jenkins_mount:/var/jenkins_mount /var/jenkins_home目录为容器jenkins工作目录,我们将硬盘上的一个目录挂载到这个位置,方便后续更新镜像后继续使用原来的工作目录。这里我们设置的就是上面我们创建的 /var/jenkins_mount目录
- -v /etc/localtime:/etc/localtime让容器使用和服务器同样的时间设置。
- –name myjenkins 给容器起一个别名
? ~ docker run -d -p 10240:8080 -p 10241:50000 -v /var/jenkins_mount:/var/jenkins_home -v /etc/localtime:/etc/localtime --name myjenkins jenkins/jenkins
e62f855f38a8b801880a2deaa7ffb00ec80aa5eb2787ae613288a6f609285acd
? ~ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e62f855f38a8 jenkins/jenkins "/sbin/tini -- /usr/…" 16 seconds ago Up 15 seconds 0.0.0.0:10240->8080/tcp, 0.0.0.0:10241->50000/tcp myjenkins
3.4 查看日志
? ~ docker logs myjenkins
Running from: /usr/share/jenkins/jenkins.war
webroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
2022-01-23 14:58:35.548+0000 [id=1] INFO org.eclipse.jetty.util.log.Log
2022-01-23 14:58:35.616+0000 [id=1] INFO winstone.Logger
2022-01-23 14:58:50.791+0000 [id=1] WARNING o.e.j.s.handler.ContextHandler
2022-01-23 14:58:50.850+0000 [id=1] INFO org.eclipse.jetty.server.Server
2022-01-23 14:58:51.470+0000 [id=1] INFO o.e.j.w.StandardDescriptorProcessor
2022-01-23 14:58:51.561+0000 [id=1] INFO o.e.j.s.s.DefaultSessionIdManager
2022-01-23 14:58:51.561+0000 [id=1] INFO o.e.j.s.s.DefaultSessionIdManager
2022-01-23 14:58:51.562+0000 [id=1] INFO o.e.j.server.session.HouseKeeper
2022-01-23 14:58:52.743+0000 [id=1] INFO hudson.WebAppMain
2022-01-23 14:58:53.216+0000 [id=1] INFO o.e.j.s.handler.ContextHandler
2022-01-23 14:58:53.249+0000 [id=1] INFO o.e.j.server.AbstractConnector
2022-01-23 14:58:53.249+0000 [id=1] INFO org.eclipse.jetty.server.Server
2022-01-23 14:58:53.250+0000 [id=24] INFO winstone.Logger
2022-01-23 14:58:54.102+0000 [id=31] INFO jenkins.InitReactorRunner$1
2022-01-23 14:58:54.205+0000 [id=36] INFO jenkins.InitReactorRunner$1
2022-01-23 14:58:56.340+0000 [id=32] INFO jenkins.InitReactorRunner$1
2022-01-23 14:58:56.350+0000 [id=39] INFO jenkins.InitReactorRunner$1
2022-01-23 14:58:56.370+0000 [id=30] INFO jenkins.InitReactorRunner$1
2022-01-23 14:58:57.274+0000 [id=30] INFO jenkins.InitReactorRunner$1
2022-01-23 14:58:57.275+0000 [id=32] INFO jenkins.InitReactorRunner$1
2022-01-23 14:58:57.275+0000 [id=32] INFO jenkins.InitReactorRunner$1
2022-01-23 14:58:57.278+0000 [id=32] INFO jenkins.InitReactorRunner$1
2022-01-23 14:58:57.303+0000 [id=53] INFO hudson.model.AsyncPeriodicWork
2022-01-23 14:58:57.339+0000 [id=53] INFO hudson.util.Retrier
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/var/jenkins_home/war/WEB-INF/lib/groovy-all-2.4.21.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2022-01-23 14:58:58.365+0000 [id=36] INFO jenkins.install.SetupWizard
*************************************************************
*************************************************************
*************************************************************
Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:
d8722ddc05464738bf0c6c2b4e8922f7
This may also be found at: /var/jenkins_home/secrets/initialAdminPassword
*************************************************************
*************************************************************
*************************************************************
3.5 修改源地址
如果拉取内容比较慢,可以尝试更换镜像加速地址。 由于配置了volumes,因此不需要登陆容器就可以修改配置,进入/var/jenkins_mount 修改hudson.model.UpdateCenter.xml为
<?xml version='1.1' encoding='UTF-8'?>
<sites>
<site>
<id>default</id>
<url>https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json</url>
</site>
</sites>
3.6 访问主页面
localhost:10240 进入容器内地址或者挂载地址获取密码并输入,安装一堆插件后 这里我没有设置管理员用户,使用的是admin账户。
|