docker-compose方式安装运行Jenkins
服务器系统:centos 7.6
以docker-compose 编排容器方式安装,当然需提前安装docker-compose环境(见百度->docker-compose环境安装)
docker-compose.yml
version: '3.1'
services:
jenkins:
image: jenkins/jenkins:2.361.3
volumes:
- /data/jenkins/:/var/jenkins_home
- /var/run/docker.sock:/var/run/docker.sock
- /usr/bin/docker:/usr/bin/docker
- /usr/lib/x86_64-linux-gnu/libltdl.so.7:/usr/lib/x86_64-linux-gnu/libltdl.so.7
ports:
- "8080:8080"
expose:
- "8080"
- "50000"
privileged: true
user: root
restart: always
container_name: jenkins
environment:
JAVA_OPTS: '-Djava.util.logging.config.file=/var/jenkins_home/log.properties'
1.上传到任意一个目录
2.执行部署Jenkins命令
docker-compose up –d
运行完成后,Jenkins已经在后台运行起来了
docker ps
使用服务器ip 地址+端口号浏览器打开
http://192.168.1.183:8080/
进入Jenkins容器查看密码
docker exec -it jenkins /bin/bash
cat /var/jenkins_home/secrets/initialAdminPassword
一直往下走进入主界面
3.进入设置全局工具配置
Jenkins容器中自带git
/usr/bin/git
Jenkins容器中自带jdk
/opt/java/openjdk
需要从外面导入maven到容器中
docker cp apache-maven-3.9.2-bin.zip cf09b3515f61:/usr/local/maven
docker exec -it jenkins /bin/bash
cd /usr/local/maven/
unzip apache-maven-3.9.2-bin.zip
拿到maven路径后配置到Jenkins 中
/usr/local/maven/apache-maven-3.9.2
或者在docker-compose.yml直接挂载数据卷
- /usr/local/maven/apache-maven-3.9.2/:/usr/local/maven/apache-maven-3.9.2
docker-compose.yml
version: '3.1'
services:
jenkins:
image: jenkins/jenkins:2.361.3
volumes:
- /data/jenkins/:/var/jenkins_home
- /usr/local/maven/apache-maven-3.9.2/:/usr/local/maven/apache-maven-3.9.2
- /var/run/docker.sock:/var/run/docker.sock
- /usr/bin/docker:/usr/bin/docker
- /usr/lib/x86_64-linux-gnu/libltdl.so.7:/usr/lib/x86_64-linux-gnu/libltdl.so.7
ports:
- "8080:8080"
expose:
- "8080"
- "50000"
privileged: true
user: root
restart: always
container_name: jenkins
environment:
JAVA_OPTS: '-Djava.util.logging.config.file=/var/jenkins_home/log.properties'
maven 设置打包时下载依赖包路径 Repository
/usr/local/maven/apache-maven-3.9.2/conf/settings.xml
<localRepository>/usr/local/maven/apache-maven-3.9.2/Repository</localRepository>
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
<localRepository>/usr/local/maven/apache-maven-3.9.2/Repository</localRepository>
<!-- interactiveMode
| This will determine whether maven prompts you when it needs input. If set to false,
| maven will use a sensible default value, perhaps based on some other setting, for
| the parameter in question.
|
| Default: true
<interactiveMode>true</interactiveMode>
-->
设置 阿里云仓库
<mirror>
<id>maven-default-http-blocker</id>
<mirrorOf>external:http:*</mirrorOf>
<name>Pseudo repository to mirror external repositories initially using HTTP.</name>
<url>http://0.0.0.0/</url>
<blocked>true</blocked>
</mirror>
<!-- 阿里云仓库,也可以在pom中设置仓库地址 -->
<mirrors>
<mirror>
<id>aliyun</id>
<name>aliyun Maven</name>
<mirrorOf>*</mirrorOf>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
</mirrors>
</mirrors>
4.快乐的构建版本