环境:
centos7.9
jenkins/jenkins:lts-jdk11
**1、拉去jenkins镜像,**请指明版本号
[root@localhost ~]# docker pull jenkins/jenkins:lts
开始拉取
拉取完成
[root@localhost ~]# docker pull jenkins/jenkins:lts
lts: Pulling from jenkins/jenkins
0a96bdb82805: Pull complete
b5e2db483aae: Pull complete
72b137db2cdf: Pull complete
d0aac1e9e20c: Pull complete
c48e3974586c: Pull complete
d281eadf0ae3: Pull complete
be47ab5dc59d: Pull complete
c09c222384de: Pull complete
a91f2a3bb141: Pull complete
1a17773e6697: Pull complete
b535e1c5efef: Pull complete
3cfa79b75794: Pull complete
Digest: sha256:dc56634cc8fa476f36eba16d7db6c6bc1f5e3c7062432256738a008a339ee95c
Status: Downloaded newer image for jenkins/jenkins:lts
docker.io/jenkins/jenkins:lts
查看镜像,已经成功拉取
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
jenkins/jenkins lts 44c1caefd796 2 weeks ago 468MB
tomcat latest f7737eeed429 2 weeks ago 468MB
mysql 8.0 6c55ddbef969 3 months ago 591MB
mysql 5.7 5107333e08a8 13 months ago 501MB
现在镜像拉取下来了,但是气门如果要启动对应的服务,需要创建一个容器,所有的操作全部在容器中进行,这个要是看不懂,可以自己搜索docker里面的知识点看看,这里不做详细阐述
在服务器上先创建一个jenkins工作目录 /var/jenkins_mount,赋予相应权限,稍后我们将jenkins容器目录挂载到这个目录上,这样我们就可以很方便地对容器内的配置文件进行修改
mkdir -p /var/jenkins_mount
chmod 777 /var/jenkins_mount
mkdir /var/jenkins_home
chmod 777 /var/jenkins_home
当通过 docker run
命令启动 Jenkins 容器并使用 -v /var/jenkins_mount:/var/jenkins_home
参数时,这表示将宿主机上的 /var/jenkins_mount
目录挂载到容器内的 /var/jenkins_home
路径下
主机目录与容器内目录的关系
-
持久化存储 :Jenkins 将所有配置文件、插件数据以及构建历史记录保存在
/var/jenkins_home
下。因此,在宿主机上创建对应的挂载点可以确保即使删除容器后这些重要资料也不会丢失。docker run --restart always -d -uroot -p 8080:8080 -p 50001:50000 -v /var/jenkins_mount:/var/jenkins_home -v /etc/localtime:/etc/localtime --name=jenkins002 jenkins/jenkins:latest
这里我创建了一个jenkins001的容器,两个映射主机的端口分别为8080和50001,因为别的80、81 和50000我这里已经为别的容器服务期动画的时候制定了,为了防止端口被占用,
通过本队浏览器访问http://192.168.37.128:8080/
输入一下密码。
访问到了以后输入密码:
docker logs jenkins002
[root@localhost ~]# docker logs jenkins002
Running from: /usr/share/jenkins/jenkins.war
webroot: /var/jenkins_home/war
2025-01-23 04:19:31.809+0000 [id=1] INFO winstone.Logger#logInternal: Beginning extraction from war file
2025-01-23 04:19:32.133+0000 [id=1] WARNING o.e.j.ee9.nested.ContextHandler#setContextPath: Empty contextPath
2025-01-23 04:19:32.373+0000 [id=1] INFO org.eclipse.jetty.server.Server#doStart: jetty-12.0.16; built: 2024-12-09T21:02:54.535Z; git: c3f88bafb4e393f23204dc14dc57b042e84debc7; jvm 17.0.13+11
2025-01-23 04:19:34.099+0000 [id=1] INFO o.e.j.e.w.StandardDescriptorProcessor#visitServlet: NO JSP Support for /, did not find org.eclipse.jetty.ee9.jsp.JettyJspServlet
2025-01-23 04:19:34.277+0000 [id=1] INFO o.e.j.s.DefaultSessionIdManager#doStart: Session workerName=node0
2025-01-23 04:19:36.185+0000 [id=1] INFO hudson.WebAppMain#contextInitialized: Jenkins home directory: /var/jenkins_home found at: EnvVars.masterEnvVars.get("JENKINS_HOME")
2025-01-23 04:19:36.654+0000 [id=1] INFO o.e.j.s.handler.ContextHandler#doStart: Started oeje9n.ContextHandler$CoreContextHandler@5173200b{Jenkins v2.494,/,b=file:///var/jenkins_home/war/,a=AVAILABLE,h=oeje9n.ContextHandler$CoreContextHandler$CoreToNestedHandler@25c5e994{STARTED}}
2025-01-23 04:19:36.723+0000 [id=1] INFO o.e.j.server.AbstractConnector#doStart: Started ServerConnector@72458efc{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
2025-01-23 04:19:36.778+0000 [id=1] INFO org.eclipse.jetty.server.Server#doStart: Started oejs.Server@506ae4d4{STARTING}[12.0.16,sto=0] @7421ms
2025-01-23 04:19:36.793+0000 [id=24] INFO winstone.Logger#logInternal: Winstone Servlet Engine running: controlPort=disabled
2025-01-23 04:19:37.110+0000 [id=23] INFO jenkins.model.Jenkins#<init>: Starting version 2.494
2025-01-23 04:19:37.447+0000 [id=29] INFO jenkins.InitReactorRunner$1#onAttained: Started initialization
2025-01-23 04:19:37.637+0000 [id=30] INFO jenkins.InitReactorRunner$1#onAttained: Listed all plugins
2025-01-23 04:19:41.142+0000 [id=30] INFO jenkins.InitReactorRunner$1#onAttained: Prepared all plugins
2025-01-23 04:19:41.164+0000 [id=30] INFO jenkins.InitReactorRunner$1#onAttained: Started all plugins
2025-01-23 04:19:41.268+0000 [id=29] INFO jenkins.InitReactorRunner$1#onAttained: Augmented all extensions
2025-01-23 04:19:42.519+0000 [id=30] INFO jenkins.InitReactorRunner$1#onAttained: System config loaded
2025-01-23 04:19:42.522+0000 [id=30] INFO jenkins.InitReactorRunner$1#onAttained: System config adapted
2025-01-23 04:19:42.538+0000 [id=30] INFO jenkins.InitReactorRunner$1#onAttained: Loaded all jobs
2025-01-23 04:19:42.540+0000 [id=30] INFO jenkins.InitReactorRunner$1#onAttained: Configuration for all jobs updated
2025-01-23 04:19:42.677+0000 [id=30] INFO jenkins.install.SetupWizard#init:
*************************************************************
*************************************************************
*************************************************************
Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:
677f8951f94646f5a4e2224746985c7d
This may also be found at: /var/jenkins_home/secrets/initialAdminPassword
*************************************************************
*************************************************************
*************************************************************
2025-01-23 04:19:56.690+0000 [id=30] INFO jenkins.InitReactorRunner$1#onAttained: Completed initialization
2025-01-23 04:19:56.897+0000 [id=23] INFO hudson.lifecycle.Lifecycle#onReady: Jenkins is fully up and running
[root@localhost ~]#
然后进入该界面
创建一个用户,不想创建的使用admin也行