当前位置: 首页 > 图灵资讯 > 技术篇> Docker部署jenkins

Docker部署jenkins

来源:图灵教育
时间:2023-06-18 09:20:48

先删除与系统docker相关的依赖

yum remove docker \                  docker-client \                  docker-client-latest \                  docker-common \                  docker-latest \                  docker-latest-logrotate \                  docker-logrotate \                  docker-engine

docker安装依赖于相关依赖性

yum install -y yum-utils

配置docker镜像地址

yum-config-manager \--add-repo \http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repoyum install -y docker-ce-20.10.7 docker-ce-cli-20.10.7  containerd.io-1.4.6

创建docker目录并配置

mkdir -p /etc/docker

tee /etc/docker/daemon.json <<-'EOF'{  "registry-mirrors": ["https://w6rlizew.mirror.aliyuncs.com"],  "exec-opts": ["native.cgroupdriver=systemd"],  "log-driver": "json-file",  "log-opts": {    "max-size": "100m"  },  "storage-driver": "overlay2"EOF

docker命令启动和关闭:

systemctl start dockersystemctl enable docker

修改主机名称,关闭并启动防火墙

hostnamectl set-hostname k8s-master && bash #修改主机名称systemctllltlllet stop firewalldsystemctl disable firewalld

JDK和Maven配置

cd /etc/profileexport JAVA_HOME=/usr/local/jdk1.8.0_371export JRE_HOME=${JAVA_HOME}/jreexport CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATHexport JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/binexport MAVEN_HOME=/usr/local/maven/apache-maven-3.6.3export PATH=${MAVEN_HOME}/bin:${JAVA_PATH}:${PATH}## 执行命令sourcece执行命令 /etc/profile

使用docker操作jenkins

docker start jenkins  ## 开启jenkinsdocker stop jenkins  ## 停止jenkinsdocker rm jenkins ## 删除jenkins镜像## 操作jenkinsdocker run -d -uroot -p 8080:8080 -p 50000:50000 -p 8888:8888 --name jenkins -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):/usr/bin/docker -v /data/jenkins/jenkins:/var/jenkins -v /data/jenkins/jenkins_home:/var/jenkins_home -v /etc/localtime:/etc/localtime -v /usr/local/jdk-11.0.19:/usr/local/jdk-11.0.19 -v /usr/local/maven/apache-maven-3.6.3:/usr/local/maven/apache-maven-3.6.3 -v /etc/profile:/etc/profile jenkins/jenkins