记录jenkins的docker安装
记录jenkins的docker安装
原来一直使用rpm包或者yum的方式安装jenkins,但是现在时不时有新的项目需要重新部署独立的jenkins,就很烦。想到docker的方便快捷,外加官方也提供docker安装包,那就先试试吧。
安装docker环境
根据官方提供的安装说明安装步骤如下:
- 首先移除旧的docker版本:
yum remove docker\
docker-client\
docker-client-latest\
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
- 安装yum-utils模块
yum install -y yum-utils
- 安装官方源:
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
- 允许使用测试版本(这里我遇到个很奇葩的问题,我用的centos8.0系统,安装docker-ce.19.03.13-3.el8的版本始终无法启动dockerserver,看了个中日志,网上查了各种方法都不行,然后启用了测试版本20.10.0-beta1瞬间啥问题都没了。。。所以各位在自己的环境如果遇到实在无法解决的问题,不放考虑换个版本安装,当然生产环境最好不要用beta版,去试试旧的稳定版本。)
yum-config-manager --enable docker-ce-test
yum-config-manager --enable docker-ce-nightly
- 安装docker最新版并启动:
yum install docker-ce docker-ce-cli containerd.io
systemctl start docker
docker version
#如果显示以下内容,则说明安装成功。
Client: Docker Engine - Community
Version: 20.10.0-beta1
API version: 1.41
Go version: go1.13.15
Git commit: ac365d7
Built: Tue Oct 13 18:16:10 2020
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.0-beta1
API version: 1.41 (minimum version 1.12)
Go version: go1.13.15
Git commit: 9c15e82
Built: Tue Oct 13 18:14:37 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.1
GitCommit: c623d1b36f09f8ef6536a057bd658b3aa8632828
runc:
Version: 1.0.0-rc92
GitCommit: ff819c7e9184c13b7c2607fe6c30ae19403a7aff
docker-init:
Version: 0.19.0
GitCommit: de40ad0
接下来就开始安装jenkins了
- 首先查询下官方的docker镜像:
# docker search jenkins
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
jenkins Official Jenkins Docker image 4970 [OK]
jenkins/jenkins The leading open source automation server 2298
jenkinsci/blueocean https://jenkins.io/projects/blueocean 578
jenkinsci/jenkins Jenkins Continuous Integration and Delivery … 383
jenkins/jnlp-slave a Jenkins agent which can connect to Jenkins… 134 [OK]
jenkinsci/jnlp-slave A Jenkins slave using JNLP to establish conn… 128 [OK]
jenkinsci/slave Base Jenkins slave docker image 65 [OK]
jenkinsci/ssh-slave A Jenkins SSH Slave docker image 43 [OK]
jenkins/slave base image for a Jenkins Agent, which includ… 42 [OK]
jenkins/ssh-slave A Jenkins slave using SSH to establish conne… 34 [OK]
cloudbees/jenkins-enterprise CloudBees Jenkins Enterprise (Rolling releas… 34 [OK]
bitnami/jenkins Bitnami Docker Image for Jenkins 28 [OK]
h1kkan/jenkins-docker 🤖 Extended Jenkins docker image, bundled wi… 27
xmartlabs/jenkins-android Jenkins image for Android development. 27 [OK]
openshift/jenkins-2-centos7 A Centos7 based Jenkins v2.x image for use w… 23
cloudbees/jenkins-operations-center CloudBees Jenkins Operation Center (Rolling … 14 [OK]
vfarcic/jenkins-swarm-agent Jenkins agent based on the Swarm plugin 8 [OK]
openshift/jenkins-slave-base-centos7 A Jenkins slave base image. DEPRECATED: see … 7
trion/jenkins-docker-client Jenkins CI server with docker client 6 [OK]
publicisworldwide/jenkins-slave Jenkins Slave based on Oracle Linux 5 [OK]
openshift/jenkins-1-centos7 DEPRECATED: A Centos7 based Jenkins v1.x ima… 4
ansibleplaybookbundle/jenkins-apb An APB which deploys Jenkins CI 1 [OK]
amazeeio/jenkins-slave A jenkins slave that connects to a master vi… 0 [OK]
jameseckersall/jenkins docker-jenkins (based on openshift jenkins 2… 0 [OK]
mashape/jenkins Just a jenkins image with the AWS cli added … 0 [OK]
这里看到很多镜像,如果需要详细的信息要去官方的镜像站查看https://hub.docker.com/。
这里我直接用了第一个,官方的镜像包。
docker pull jenkins
- 先新建一个文件夹作为持久化存储的目录,并且要赋予他所有人可读写的权限
mkdir /var/jenkins
chmod -R a+rw /var/jenkins
- 然后用官方镜像创建容器(这里为了以后没有那么多权限的问题,我使用的root用户来运行,并根据官方的文档映射对应的端口):
docker run -d -u root --name myjenkins -p 8080:8080 -p 50000:50000 -v /var/jenkins:/var/jenkins_home jenkins
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1e8892a028cd jenkins "/bin/tini -- /usr/l…" 16 hours ago Up 16 hours 0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp myjenkins
这样就运行起来了 ,这时候访问本机ip+端口就能打开jenkins进行初始化了
初始化的密码可以在日志里查看:
docker logs myjenkins
如果刷新看不到了,可以在/var/lib/docker/containers/容器ID/容器ID-json.log里查看。
这里说个问题,如果你在初始化得时候所有的插件都不能安装,没关系,跳过。进入系统以后,在“系统管理”-“插件管理”-“高级”这个页面的下面有个升级站点的URL,把它替换成清华的jenkins源 https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json 然后提交在可更新这里选择立即获取,等一会就能在这里选择你想安装或者升级的插件了。
全文完,如果有什么问题可以留言,我们一起讨论。