docker-compose安装Jenkins的实践笔记
创建目录
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')
安装完成
到此这篇关于docker-compose安装Jenkins的文章就介绍到这了,更多相关docker-compose安装Jenkins内容请搜索海外IDC网以前的文章或继续浏览下面的相关文章希望大家【来源:美国cn2服务器http://www.558idc.com/mg.html 转载请说明出处】以后多多支持海外IDC网!