docker安装jenkins

1.下载镜像

docker pull jenkins/jenkins

2.创建挂载目录并授权

mkdir docker_vm
chmod 777 /usr/local/application/docker_vm

2.挂载并启动

docker run -d -p 10240:8080 -p 10241:50000 -v /usr/local/application/docker_vm:/var/jenkins_home -v /etc/localtime:/etc/localtime --name myjenkins jenkins/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 给容器起一个别名

3. 启动后查看日志

docker logs myjenkins
Running from: /usr/share/jenkins/jenkins.war
webroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
2021-09-08 08:32:30.202+0000 [id=1] INFO    org.eclipse.jetty.util.log.Log#initialized: Logging initialized @1009ms to org.eclipse.jetty.util.log.JavaUtilLog
2021-09-08 08:32:30.357+0000 [id=1] INFO    winstone.Logger#logInternal: Beginning extraction from war file
2021-09-08 08:32:31.824+0000 [id=1] WARNING o.e.j.s.handler.ContextHandler#setContextPath: Empty contextPath
2021-09-08 08:32:32.015+0000 [id=1] INFO    org.eclipse.jetty.server.Server#doStart: jetty-9.4.43.v20210629; built: 2021-06-30T11:07:22.254Z; git: 526006ecfa3af7f1a27ef3a288e2bef7ea9dd7e8; jvm 11.0.12+7
2021-09-08 08:32:32.525+0000 [id=1] INFO    o.e.j.w.StandardDescriptorProcessor#visitServlet: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet
2021-09-08 08:32:32.613+0000 [id=1] INFO    o.e.j.s.s.DefaultSessionIdManager#doStart: DefaultSessionIdManager workerName=node0
2021-09-08 08:32:32.614+0000 [id=1] INFO    o.e.j.s.s.DefaultSessionIdManager#doStart: No SessionScavenger set, using defaults
2021-09-08 08:32:32.616+0000 [id=1] INFO    o.e.j.server.session.HouseKeeper#startScavenging: node0 Scavenging every 600000ms
2021-09-08 08:32:33.538+0000 [id=1] INFO    hudson.WebAppMain#contextInitialized: Jenkins home directory: /var/jenkins_home found at: EnvVars.masterEnvVars.get("JENKINS_HOME")
2021-09-08 08:32:33.981+0000 [id=1] INFO    o.e.j.s.handler.ContextHandler#doStart: Started w.@47af099e{Jenkins v2.309,/,file:///var/jenkins_home/war/,AVAILABLE}{/var/jenkins_home/war}
2021-09-08 08:32:34.027+0000 [id=1] INFO    o.e.j.server.AbstractConnector#doStart: Started ServerConnector@45c8d09f{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
2021-09-08 08:32:34.028+0000 [id=1] INFO    org.eclipse.jetty.server.Server#doStart: Started @4839ms
2021-09-08 08:32:34.041+0000 [id=23]    INFO    winstone.Logger#logInternal: Winstone Servlet Engine running: controlPort=disabled
2021-09-08 08:32:34.438+0000 [id=30]    INFO    jenkins.InitReactorRunner$1#onAttained: Started initialization
2021-09-08 08:32:34.505+0000 [id=29]    INFO    jenkins.InitReactorRunner$1#onAttained: Listed all plugins
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$2 (file:/var/jenkins_home/war/WEB-INF/lib/guice-4.0.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$2
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
2021-09-08 08:32:36.919+0000 [id=28]    INFO    jenkins.InitReactorRunner$1#onAttained: Prepared all plugins
2021-09-08 08:32:36.934+0000 [id=28]    INFO    jenkins.InitReactorRunner$1#onAttained: Started all plugins
2021-09-08 08:32:36.957+0000 [id=29]    INFO    jenkins.InitReactorRunner$1#onAttained: Augmented all extensions
2021-09-08 08:32:38.161+0000 [id=29]    INFO    jenkins.InitReactorRunner$1#onAttained: System config loaded
2021-09-08 08:32:38.162+0000 [id=29]    INFO    jenkins.InitReactorRunner$1#onAttained: System config adapted
2021-09-08 08:32:38.167+0000 [id=29]    INFO    jenkins.InitReactorRunner$1#onAttained: Loaded all jobs
2021-09-08 08:32:38.168+0000 [id=29]    INFO    jenkins.InitReactorRunner$1#onAttained: Configuration for all jobs updated
2021-09-08 08:32:38.263+0000 [id=44]    INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Started Download metadata
2021-09-08 08:32:38.310+0000 [id=44]    INFO    hudson.util.Retrier#start: Attempt #1 to do the action check updates server
2021-09-08 08:32:39.245+0000 [id=29]    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:
685864e89b064698917db6a7c93173da
This may also be found at: /var/jenkins_home/secrets/initialAdminPassword
*************************************************************
*************************************************************
*************************************************************

4. 配置镜像加速

cd /usr/local/application/docker_vm

修改hudson.model.UpdateCenter.xml里的内容:

vi  hudson.model.UpdateCenter.xml

将 url 修改为 清华大学官方镜像:https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json



  
    default
    https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json
  

5. 访问Jenkins页面,输入你的ip加上10240

image.png

获取密码:

cat /usr/local/application/docker_vm/secrets/initialAdminPassword

6. 安装插件

选择推荐即可,安装失败的直接跳过


image.png

7. 创建用户

image.png

完成后即可!

你可能感兴趣的:(docker安装jenkins)