docker-compose安装Jenkins docker-compose安装Jenkins的实践笔记
゛ゞ旁觀者ヾ 人气:0想了解docker-compose安装Jenkins的实践笔记的相关内容吗,゛ゞ旁觀者ヾ在本文为您仔细讲解docker-compose安装Jenkins的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:docker-compose安装Jenkins,docker-compose安装,下面大家一起来学习吧。
创建目录
cd /usr/local/docker/ mkdir jenkins-docker cd jenkins-docker
创建Dockerfile
vi Dockerfile # 以下是文件内容 FROM jenkins/jenkins:lts USER root RUN mkdir -p /usr/local/ && \ cd /usr/local/ && \ curl -fsSL https://mirror.bit.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz > /usr/local/apache-maven-3.6.3-bin.tar.gz && \ tar xzf /usr/local/apache-maven-3.6.3-bin.tar.gz -C /usr/local/ && \ rm -rf /usr/local/apache-maven-3.6.3-bin.tar.gz && \ ln -s /usr/local/apache-maven-3.6.3/bin/mvn /bin/mvn && \ ln -s /usr/local/apache-maven-3.6.3/bin/mvnyjp /bin/mvnyjp && \ export PATH=/usr/local/apache-maven-3.6.3/bin:$PATH USER jenkins
构建镜像
docker build -t jenkins-jiacs:lts .
查看Docker在宿主机的Group ID
cat /etc/group | grep docker # [root@localhost jenkins-docker]# cat /etc/group | grep docker # docker:x:994: # 我这里的是994,根据各自的实际值而定
启动Jenkins容器(docker命令行启动)
# 启动容器之前先创建 /usr/local/docker/jenkins-docker/data 文件夹并赋予权限 # /usr/local/docker/jenkins-docker/config/settings.xml 该文件自行提供(可自定义私服等信息) mkdir data chmod -R 777 data docker run -d -p 8080:8080 -p 50000:50000 \ -v /usr/local/docker/jenkins-docker/data:/var/jenkins_home \ -v /etc/localtime:/etc/localtime:ro \ -v /var/run/docker.sock:/var/run/docker.sock \ -v /etc/docker:/etc/docker \ -v /usr/bin/docker:/usr/bin/docker \ -v /usr/local/bin/docker-compose:/usr/local/bin/docker-compose \ -v /usr/local/docker/jenkins-docker/config/settings.xml:/usr/local/apache-maven-3.6.3/conf/settings.xml \ --group-add=994 \ --name my-jenkins \ jenkins-jiacs:lts # 说明: # 1. -v /usr/local/docker/jenkins-docker/data:/var/jenkins_home =》持久化Jenkins数据 # 2. -v /etc/localtime:/etc/localtime:ro =》 设置Jenkins容器时间和宿主机一致 # 3. -v /etc/docker:/etc/docker =》 Jenkins容器中使用的docker为宿主机安装的docker,保证Jenkins部署的服务是在宿主机中启动的 # 4. -v /usr/local/bin/docker-compose:/usr/local/bin/docker-compose 如果宿主机安装了docker-compose,Jenkins容器需要使用的话可以加上该数据卷 # -v /usr/local/docker/jenkins-docker/config/settings.xml:/usr/local/apache-maven-3.6.3/conf/settings.xml # --group-add=994 让启动的容器用户组设置为宿主机中docker的用户组,保证在Jenkins容器中有权限操作宿主机的docker命令
启动Jenkins容器(docker-compose启动)
cd /usr/local/docker/jenkins-docker vi jenkins-docker.yaml
version: '2' # 版本号不要修改,有些版本不支持group_add参数 services: jenkins: image: 'jenkins-jiacs:lts' container_name: my-jenkins # restart: always ports: - '8080:8080' - '50000:50000' group_add: - 994 volumes: - ./data:/var/jenkins_home - /etc/localtime:/etc/localtime:ro - /var/run/docker.sock:/var/run/docker.sock - /etc/docker:/etc/docker - /usr/bin/docker:/usr/bin/docker - /usr/local/bin/docker-compose:/usr/local/bin/docker-compose - ./config/settings.xml:/usr/local/apache-maven-3.6.3/conf/settings.xml
启动
docker-compose -f jenkins-docker.yaml up -d
查看容器
docker ps
进入容器
docker exec -it 0d8b70ba5cec bash # 查看Jenkins初始密码(在容器中执行) cat /var/jenkins_home/secrets/initialAdminPassword
打开浏览器访问Jenkins服务
http://<宿主机IP>:8080/
将刚才查到的初始密码,填入
选择安装推荐的插件,等待插件的安装(这里耗时会久一点),如果部分插件安装失败,可以点击重试继续安装,或者记录失败的插件,到系统配置-插件配置中手动安装
修改Jenkins时区
系统管理 > 脚本命令行,输入一下命令,点击【运行】
System.setProperty('org.apache.commons.jelly.tags.fmt.timeZone', 'Asia/Shanghai')
安装完成
加载全部内容