🎈 作者:互联网-小啊宇 🎈 简介: CSDN 运维领域创作者。目前从事 Kubernetes运维相关工作,擅长Linux系统运维、开源监控软件维护、Kubernetes容器技术、CI/CD持续集成、自动化运维、开源软件部署维护等领域。 🎈 博客首页:互联网-小啊宇
systemctl stop firewalld && systemctl disable firewalld && setenforce 0 && iptables -F && iptables-save
yum -y remove docker docker-common docker-selinux docker-engine docker-engine-selinux container-selinux docker-ce
# 或者
yum -y remove docker*
#删除所有的镜像、容器、数据卷、配置文件等
sudo rm -rf /var/lib/docker
# 查看安装的docker相关软件 卸载情况
yum list installed | grep docker
yum install -y yum-utils
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum list docker-ce --showduplicates|sort -r
docker-ce.x86_64 3:18.09.6-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.5-3.el7 docker-ce-stable
docker-ce.x86_64 18.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 18.03.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.12.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.3.ce-1.el7 docker-ce-stable
yum install docker-ce-17.06.2.ce-1.el7.centos
[root@localhost ~]# docker search jenkins
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
jenkins DEPRECATED; use "jenkins/jenkins:lts" instead 5504 [OK]
jenkins/jenkins The leading open source automation server 3087
jenkins/jnlp-slave a Jenkins agent which can connect to Jenki... 150 [OK]
jenkins/inbound-agent 65
bitnami/jenkins Bitnami Docker Image for Jenkins 53 [OK]
jenkins/slave base image for a Jenkins Agent, which incl... 48 [OK]
jenkins/agent 39
jenkins/ssh-slave A Jenkins slave using SSH to establish con... 38 [OK]
jenkins/ssh-agent Docker image for Jenkins agents connected ... 24
jenkins/jnlp-agent-docker 8
jenkins/jnlp-agent-maven A JNLP-based agent with Maven 3 built in 7
jenkins/pct Plugin Compat Tester 5 [OK]
jenkins/evergreen An automatically self-updating Jenkins dis... 5
jenkins/jenkins-experimental Experimental images of Jenkins. These imag... 3 [OK]
jenkins/jnlp-agent-python A JNLP-based agent with Python built in 3
jenkins/jnlp-agent-alpine 2
jenkins/ath Jenkins Acceptance Test Harness 1 [OK]
jenkins/jenkinsfile-runner Jenkinsfile Runner packages 1
rancher/jenkins-jenkins 1
jenkins/core-pr-tester Docker image for testing pull-requests sen... 1
jenkins/jnlp-agent-node 1
jenkins/jnlp-agent-ruby 1
rancher/jenkins-master Jenkins Server 1 [OK]
rancher/jenkins-slave Jenkins Build Slave 0 [OK]
rancher/jenkins-jnlp-slave 0
选择第二个版本的镜像,因为这个是 Jenkins 官网里面推荐的 Docker 镜像,同时第一个也提示已经废弃了。
docker pull jenkins/jenkins
该命令直接拉取的最新版本(latest)的镜像,我们还可以选择下面几个推荐的版本:
更多 TAG 版本的 Jenkins 可以查看 Docker Hub 官网:https://registry.hub.docker.com/r/jenkins/jenkins/tags
docker inspect jenkins/jenkins
mkdir -p /data/jenkins_home
chmod 777 /data/jenkins_home
注意: 创建挂载目录的同时要给该目录配置权限 777,如果权限不足的话,到时进行目录挂载的时候会失败导致无法启动 Jenkins 容器。
docker run -d \
-p 8888:8080 \
-p 50000:50000 \
-v /data/jenkins_home:/var/jenkins_home \
-v /etc/localtime:/etc/localtime \
--restart=always \
--name=jenkins \
jenkins/jenkins
-d
:后台运行容器;-p 8888:8080
:将容器的 8080 端口映射到服务器的 8888 端口;-p 50000:50000
:将容器的 50000 端口映射到服务器的 50000 端口;-v /data/jenkins_home:/var/jenkins_home
:将容器中 Jenkins 的工作目录挂载到服务器的/data/jenkins_home;-v /etc/localtime:/etc/localtime
:让容器使用和服务器同样的时间设置;--restart=always
:设置容器的重启策略为 Docker 重启时自动重启;--name=jenkins
:给容器起别名;查看是否在运行:
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a5f0ae5db965 jenkins/jenkins "/usr/bin/tini -- ..." 4 minutes ago Up 4 minutes 0.0.0.0:50000->50000/tcp, 0.0.0.0:8888->8080/tcp jenkins
查看启动日志:
[root@localhost ~]# docker logs jenkins
Running from: /usr/share/jenkins/jenkins.war
webroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
2022-07-07 03:06:58.305+0000 [id=1] INFO org.eclipse.jetty.util.log.Log#initialized: Logging initialized @630ms to org.eclipse.jetty.util.log.JavaUtilLog
2022-07-07 03:06:58.404+0000 [id=1] INFO winstone.Logger#logInternal: Beginning extraction from war file
...
如果没有启动成功的话,可以排查一下挂载的目录是否正确,比如是否配了目录权限等。
在访问 Jenkins 页面前,我们需要对 Jenkins 的插件配置内容修改成内容的镜像加速地址 因为目录进行了挂载,可以直接在宿主机进行修改配置
cd /data/jenkins_home/updates
sed -i 's#https://updates.jenkins.io/download#https://mirrors.tuna.tsinghua.edu.cn/jenkins#g' default.json
sed -i 's#http://www.google.com#https://www.baidu.com#g' default.json
修改配置后重启jenkins
docker restart jenkins
配置好后,访问 Jenkins 页面,地址为:IP + 容器的8080端口所映射到服务器上的端口
宿主机或者容器根据提示查看密码
宿主机路径
:/data/jenkins_home/secrets/initialAdminPassword容器路径
:/var/jenkins_home/secrets/initialAdminPassword[root@localhost ~]# cat /data/jenkins_home/secrets/initialAdminPassword
625123f5d4XXXXXXXXXe51fb897
选择安装推荐的插件即可,下面是推荐的插件安装页面:
安装完成后,会进入管理员创建页面,可以选择使用admin账户继续,也可以创建一个新的管理员用户