概述
docker部署jenkins
- 一、基础环境
- 0.说明
- 1.环境说明
- 2.镜像选择
- 二、镜像部署
- 0.部署前准备
- 1.拉取镜像
- 2.运行容器
- 3. 详细参数
- 三、docker-compose方式部署jenkins
- 1.下载配置文件
- 2.修改配置文件
一、基础环境
0.说明
此文档为docker环境下部署jenkins,包括以docker-compose方式启动。
如果有错误大佬麻烦指出
1.环境说明
部署系统:centos7.9
docker版本:20.10.16
网络环境:外网环境
硬件环境:vmware虚拟机环境
虚拟机配置:cpu-4c 内存-16G(实际上用不到这么多,只是我给的比较富裕,具体可以看自己情况自行加减)
docker镜像源:阿里镜像源
2.镜像选择
镜像名:bitnami/jenkins
dockerhub地址:https://hub.docker.com/r/bitnami/jenkins
版本选择:最新版
选择原因:jenkins官方的dockerhub已经好几年没有维护了,用的版本还是非常老的版本
所以这里用第三方开源项目bitnami的jenkins镜像
从上次更新时间来看,bitnami维护的jenkins docker镜像较为活跃。
二、镜像部署
0.部署前准备
确保docker运行正常,确定docker与dockerhub镜像仓库连接正常。
1.拉取镜像
我这边直接拉取最新版镜像
docker pull bitnami/jenkins
如果有特殊需求可以在dockerhub的tag页面拉取自己需要的版本
没有特殊需求拉取latest版本即可
命令:docker pull bitnami/jenkins
结果:
[root@cicd ~]# docker pull bitnami/jenkins
Using default tag: latest
latest: Pulling from bitnami/jenkins
0796bf144e3f: Pull complete
611583d8f27f: Pull complete
e3ae7d1a3c24: Pull complete
354b18b63610: Pull complete
9b4a65d0e880: Pull complete
63f3fe641127: Pull complete
97906d956f33: Pull complete
c5ea5a3792f2: Pull complete
de3feb83ade1: Pull complete
efacc1f406c0: Pull complete
de2f7ee0bbcd: Pull complete
Digest: sha256:be3432aab368e4f6217628cd81a8865fe476f895287a9e3d21ba44a3141f00b5
Status: Downloaded newer image for bitnami/jenkins:latest
docker.io/bitnami/jenkins:latest
查看一下,拉取成功
[root@cicd ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
bitnami/jenkins latest ef96289220b9 13 months ago 595MB
2.运行容器
创建网络
命令:docker network create jenkins-network
结果:
[root@cicd ~]# docker network create jenkins-network
1aa7879e1659e1828863107d5a7cac8a70243c83265caf665f4f2b0742c024fb
查看镜像用户权限
命令:docker inspect ef96289220b9 |grep User
结果:
[root@cicd ~]# docker inspect ef96289220b9 |grep User
"User": "1001",
"User": "1001",
创建数据目录(可自行选择创建位置)并授权给docker
如果docker容器启动时用 --privileged=true
参数则可以不用授权
命令:mkdir -p /data/jenkins
chown 1001:1001 /data/jenkins -R
结果:
[root@cicd ~]# mkdir -p /data/jenkins
[root@cicd ~]# chown 1001:1001 /data/jenkins -R
运行容器
命令:
docker run -d -p 80:8080 --name jenkins
--network jenkins-network
--volume /data/jenkins/data:/bitnami/jenkins
bitnami/jenkins:latest
结果:
[root@cicd ~]# docker run -d -p 80:8080 --name jenkins
> --network jenkins-network
> --volume /data/jenkins/data:/bitnami/jenkins
> bitnami/jenkins:latest
37cc0af8053c595d68067ae03dc57e520562d0f6065cc0453051c41f7bdbc517
查看日志:
[root@cicd ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
37cc0af8053c bitnami/jenkins:latest "/opt/bitnami/script…" 2 seconds ago Up 2 seconds 8443/tcp, 50000/tcp, 0.0.0.0:80->8080/tcp, :::80->8080/tcp jenkins
[root@cicd ~]# docker logs -f 37cc0af8053c
jenkins 08:48:14.45
jenkins 08:48:14.45 Welcome to the Bitnami jenkins container
jenkins 08:48:14.45 Subscribe to project updates by watching https://github.com/bitnami/bitnami-docker-jenkins
jenkins 08:48:14.45 Submit issues and feature requests at https://github.com/bitnami/bitnami-docker-jenkins/issues
jenkins 08:48:14.45
jenkins 08:48:14.45 INFO ==> Configuring libnss_wrapper
jenkins 08:48:14.46 INFO ==> ** Starting Jenkins setup **
realpath: /usr/share/jenkins/ref: No such file or directory
jenkins 08:48:14.52 INFO ==> Creating init script
jenkins 08:48:14.52 INFO ==> Starting Jenkins in background
jenkins 08:48:44.54 INFO ==> Stopping Jenkins
jenkins 08:48:45.54 INFO ==> ** Jenkins setup finished! **
jenkins 08:48:45.55 INFO ==> ** Starting Jenkins **
Running from: /opt/bitnami/jenkins/jenkins.war
webroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
2023-02-20 08:48:45.735+0000 [id=1] INFO org.eclipse.jetty.util.log.Log#initialized: Logging initialized @176ms to org.eclipse.jetty.util.log.JavaUtilLog
2023-02-20 08:48:45.773+0000 [id=1] INFO winstone.Logger#logInternal: Beginning extraction from war file
2023-02-20 08:48:45.788+0000 [id=1] WARNING o.e.j.s.handler.ContextHandler#setContextPath: Empty contextPath
2023-02-20 08:48:45.816+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 1.8.0_312-b07
2023-02-20 08:48:45.933+0000 [id=1] INFO o.e.j.w.StandardDescriptorProcessor#visitServlet: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet
2023-02-20 08:48:45.951+0000 [id=1] INFO o.e.j.s.s.DefaultSessionIdManager#doStart: DefaultSessionIdManager workerName=node0
2023-02-20 08:48:45.952+0000 [id=1] INFO o.e.j.s.s.DefaultSessionIdManager#doStart: No SessionScavenger set, using defaults
2023-02-20 08:48:45.952+0000 [id=1] INFO o.e.j.server.session.HouseKeeper#startScavenging: node0 Scavenging every 660000ms
2023-02-20 08:48:46.135+0000 [id=1] INFO hudson.WebAppMain#contextInitialized: Jenkins home directory: /bitnami/jenkins/home found at: EnvVars.masterEnvVars.get("JENKINS_HOME")
2023-02-20 08:48:46.172+0000 [id=1] INFO o.e.j.s.handler.ContextHandler#doStart: Started w.@791d1f8b{Jenkins v2.319.1,/,file:///bitnami/jenkins/home/war/,AVAILABLE}{/bitnami/jenkins/home/war}
2023-02-20 08:48:46.188+0000 [id=1] INFO o.e.j.server.AbstractConnector#doStart: Started ServerConnector@3a03464{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
2023-02-20 08:48:46.188+0000 [id=1] INFO org.eclipse.jetty.server.Server#doStart: Started @629ms
2023-02-20 08:48:46.188+0000 [id=22] INFO winstone.Logger#logInternal: Winstone Servlet Engine running: controlPort=disabled
2023-02-20 08:48:46.757+0000 [id=29] INFO jenkins.InitReactorRunner$1#onAttained: Started initialization
2023-02-20 08:48:46.846+0000 [id=28] WARNING hudson.ClassicPluginStrategy#createPluginWrapper: encountered /bitnami/jenkins/home/plugins/swarm-3.22.jpi under a nonstandard name; expected swarm.jpi
2023-02-20 08:48:46.862+0000 [id=28] INFO jenkins.InitReactorRunner$1#onAttained: Listed all plugins
2023-02-20 08:48:48.960+0000 [id=28] INFO jenkins.InitReactorRunner$1#onAttained: Prepared all plugins
2023-02-20 08:48:48.982+0000 [id=28] INFO jenkins.InitReactorRunner$1#onAttained: Started all plugins
2023-02-20 08:48:48.988+0000 [id=31] INFO jenkins.InitReactorRunner$1#onAttained: Augmented all extensions
2023-02-20 08:48:49.718+0000 [id=31] INFO jenkins.InitReactorRunner$1#onAttained: System config loaded
2023-02-20 08:48:49.718+0000 [id=31] INFO jenkins.InitReactorRunner$1#onAttained: System config adapted
2023-02-20 08:48:49.720+0000 [id=33] INFO jenkins.InitReactorRunner$1#onAttained: Loaded all jobs
2023-02-20 08:48:49.721+0000 [id=30] INFO jenkins.InitReactorRunner$1#onAttained: Configuration for all jobs updated
2023-02-20 08:48:49.747+0000 [id=47] INFO hudson.model.AsyncPeriodicWork#lambda$doRun$1: Started Download metadata
2023-02-20 08:48:49.749+0000 [id=47] INFO hudson.model.AsyncPeriodicWork#lambda$doRun$1: Finished Download metadata. 2 ms
2023-02-20 08:48:49.766+0000 [id=31] INFO jenkins.InitReactorRunner$1#onAttained: Completed initialization
2023-02-20 08:48:49.775+0000 [id=21] INFO hudson.WebAppMain$3#run: Jenkins is fully up and running
2023-02-20 08:53:49.008+0000 [id=61] INFO hudson.model.AsyncPeriodicWork#lambda$doRun$1: Started Periodic background build discarder
2023-02-20 08:53:49.009+0000 [id=61] INFO hudson.model.AsyncPeriodicWork#lambda$doRun$1: Finished Periodic background build discarder. 1 ms
访问:http://服务器ip:80
用户名:user
密码:bitnami
3. 详细参数
用户名
JENKINS_USERNAME: Jenkins admin username. Default: user
密码
JENKINS_PASSWORD: Jenkins admin password. Default: bitnami
邮箱
JENKINS_EMAIL: Jenkins admin email. Default: user@example.com
家目录
JENKINS_HOME: Jenkins home directory. Default: /bitnami/jenkins/home
http端口
JENKINS_HTTP_PORT_NUMBER: Port used by Jenkins for HTTP. Default: 8080
https端口
JENKINS_HTTPS_PORT_NUMBER: Port used by Jenkins for HTTPS. Default: 8443
http暴露端口
JENKINS_EXTERNAL_HTTP_PORT_NUMBER: Port to used by Jenkins to generate URLs and links when accessing using HTTP. Default: 80
https暴露端口
JENKINS_EXTERNAL_HTTPS_PORT_NUMBER: Port to used by Jenkins to generate URLs and links when accessing using HTTPS. Default: 443
JNLP端口
JENKINS_JNLP_PORT_NUMBER: Port used by Jenkins for JNLP. Default: 50000
仅启动https
JENKINS_FORCE_HTTPS: Enable serving Jenkins only through HTTPS. Default: no
跳过执行初始引导
JENKINS_SKIP_BOOTSTRAP: Skip performing the initial bootstrapping. Default: no
使用时以 --env 参数名=参数值方式启用 如:
docker run -d -p 80:8080 --name jenkins
--env JENKINS_PASSWORD=my_password
--network jenkins-network
--volume /path/to/jenkins-persistence:/bitnami/jenkins
bitnami/jenkins:latest
三、docker-compose方式部署jenkins
1.下载配置文件
找一个自定目录下载官方配置文件
命令:
curl -sSL https://raw.githubusercontent.com/bitnami/containers/main/bitnami/jenkins/docker-compose.yml > docker-compose.yml
2.修改配置文件
配置文件内容
version: '2'
services:
jenkins:
image: docker.io/bitnami/jenkins:2
ports:
- '80:8080'
environment:
- JENKINS_PASSWORD=bitnami
volumes:
- 'jenkins_data:/bitnami/jenkins'
volumes:
jenkins_data:
driver: local
根据自己需要修改配置文件
确保已经安装docker-compose后启动
docker-compose up -d
运行结果:
[root@cicd jenkins]# docker-compose up -d
[+] Running 12/12
⠿ jenkins Pulled 29.7s
⠿ 23b664af592e Pull complete 3.1s
⠿ 9780f2467d8a Pull complete 3.2s
⠿ 75f25be3b4e5 Pull complete 3.5s
⠿ 3415add13510 Pull complete 3.6s
⠿ 79ff1d6e3cce Pull complete 10.4s
⠿ 40d29eca4833 Pull complete 10.4s
⠿ 0cf3ee5e27b2 Pull complete 10.6s
⠿ beb6a9e999e0 Pull complete 13.2s
⠿ 25b8ec42c87e Pull complete 13.3s
⠿ e6909a8e3739 Pull complete 13.3s
⠿ 580e979e9d9f Pull complete 13.7s
[+] Running 2/2
⠿ Network jenkins_default Created 0.0s
⠿ Container jenkins-jenkins-1 Started 1.1s
[root@cicd jenkins]# docker-compose ps
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
jenkins-jenkins-1 docker.io/bitnami/jenkins:2 "/opt/bitnami/script…" jenkins About a minute ago Up About a minute 8443/tcp, 50000/tcp, 0.0.0.0:80->8080/tcp, :::80->8080/tcp
最后
以上就是忧郁路灯为你收集整理的docker部署jenkins一、基础环境二、镜像部署三、docker-compose方式部署jenkins的全部内容,希望文章能够帮你解决docker部署jenkins一、基础环境二、镜像部署三、docker-compose方式部署jenkins所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复