Jenkins新版本必须java11或者java17,所以选择docker方式安装,踩坑步骤如下,

安装docker就不说了还是常用yum install docker
按照官方文档一步一步最后无法安装,

E: Failed to fetch http://deb.debian.org/debian/pool/main/p/python3.9/python3.9-minimal_3.9.2-1_amd64.deb  Connection timed out [IP: 146.75.114.132 80]
E: Failed to fetch http://deb.debian.org/debian/pool/main/m/mpdecimal/libmpdec3_2.5.1-1_amd64.deb  Connection timed out [IP: 151.101.110.132 80]
E: Failed to fetch http://deb.debian.org/debian/pool/main/p/python3.9/libpython3.9-stdlib_3.9.2-1_amd64.deb  Connection timed out [IP: 151.101.110.132 80]
E: Failed to fetch http://deb.debian.org/debian/pool/main/p/python3.9/python3.9_3.9.2-1_amd64.deb  Connection timed out [IP: 146.75.114.132 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

猜测官方使用的是debian内核的docker,我是centos所以还是有点问题的。
直接去docker仓库找到Jenkins拉取最新版:

docker pull jenkins/jenkins:lts-jdk11

拉取不成功的可以使用国内加速源。我这网速还好顺利下完。
然后建立一个映射目录。我就跟常用的放一起

mkdir /var/jenkins


因为jenkins user - uid 1000所以给目录个权限

chown 1000.1000 /var/jenkins

docker run -d -v jenkins_home:/var/jenkins_home -p 8080:8080 -p 50000:50000 --restart=on-failure jenkins/jenkins:lts-jdk11

这里把jenkins_home改为/var/jenkins。这个地方我卡了一会。后来看文档才知道-v参数冒号":"前面的目录是宿主机目录,后面的目录是容器内目录
PS:容器目录不可以为相对路径----宿主机目录如果不存在,则会自动生成

docker run -d -v /var/jenkins:/var/jenkins_home -p 8080:8080 -p 50000:50000 --restart=on-failure jenkins/jenkins:lts-jdk11

成功撒花!

 

docker run -d -v /home/nfs/test/jenkins:/var/jenkins_home -p 8085:8080 -p 50000:50000 --restart=on-failure jenkins/jenkins:lts-jdk11
chown -R 1000:1000 /home/nfs/test/jenkins #容器内jenkins权限是1000