dockerfile jenkins搭建
方式一(推荐)、用最新官方镜像生成jenkins,Dockerfile如下
在linux 下
cd /home
mkdir jenkins
cd jenkins
1、新建 Dockerfile ,内容如下
FROM jenkins/jenkins:lts
COPY executors.groovy /usr/share/jenkins/ref/init.groovy.d/executors.groovy
ADD apache-maven-3.6.0-bin.tar.gz /opt/
新建 executors.groovy 文件,可将默认的2个任务进程数改为5个并发,内容如下
import jenkins.model.*
Jenkins.instance.setNumExecutors(5)
下载官方maven
wget http://mirror.bit.edu.cn/apache/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.tar.gz
2、生成镜像
docker build ./ -t myjenkins
3、运行镜像
sudo docker run --name jenkins --restart=always -d -p 8888:8080 -p 50000:50000 -u 0
-e JENKINS_OPTS="--prefix=/jenkins" -e JAVA_OPTS=-Dorg.apache.commons.jelly.tags.fmt.timeZone=Asia/Shanghai
-v /home/jenkins_home:/var/jenkins_home -v /etc/localtime:/etc/localtime myjenkins
说明 --restart=always 开启自启
-u 0 解决官方镜像数据无法映射指定文件夹的问题,此处数据存储在/home/jenkins_home文件夹下
-e JENKINS_OPTS="--prefix=/jenkins" 可以配置域名访问
-e JAVA_OPTS=Dorg.apache.commons.jelly.tags.fmt.timeZone=Asia/Shanghai 解决jenkins时间错误
替换maven配置文件为自己的maven仓库配置文件,将settings.xml 文件放在jenkins目录下,运行命令
docker cp settings.xml myjenkins:/opt/apache-maven-3.6.0/conf/
4、docker logs -f jenkins 查看一下jenkins启动日志,如果提示权限不足
运行sudo chown 1000:1000 /home/jenkins_home/
然后 docker restart jenkins
5、git和jdk 直接在jenkins上安装即可
6、访问地址: <ip>:8888/jenkins
7、也可以配置nginx域名映射,例如用 jenksin.zymreal.com 访问 ,注意要将该域名解析到此IP,
并且jenkins 系统设置Jenkins URL 配置成 http://jenkins.zymreal.com/jenkins/
server {
listen 80;
server_name jenkins.zymreal.com;
access_log /usr/local/nginx/logs/nginx.log combined;
index index.html index.htm index.php;
root /opt/nginx/html;
location / {
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8888/jenkins;
client_max_body_size 1000m;
}
location /jenkins {
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8888/jenkins;
client_max_body_size 1000m;
}
}
方式二、用最新jenkins.war包 构建jenkins ,Dockerfile如下
FROM centos:7
MAINTAINER wanghh 4456xxx@qq.com
RUN yum install wget -y
ADD apache-tomcat-9.0.10.tar.gz /opt/
ADD apache-ant-1.10.5-bin.tar.gz /opt/
ADD jdk-8u181-linux-x64.tar.gz /opt/
ADD apache-maven-3.5.4-bin.tar.gz /opt/
ENV JAVA_HOME /opt/jdk1.8.0_181
ENV ANT_HOME /opt/apache-ant-1.10.5
ENV CLASSPATH .:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV MAVEN_HOME /opt/apache-maven-3.5.4
ENV JENKINS_HOME /var/jenkins_home
ENV JAVA_TOOL_OPTIONS -Dfile.encoding=UTF-8
ENV PATH $JAVA_HOME/bin:$ANT_HOME/bin:$PATH:$MAVEN_HOME/bin:$PATH:$JENKINS_HOME
RUN yum install -y git
CMD /opt/apache-tomcat-9.0.10/bin/catalina.sh run
RUN rm -rf /etc/localtime && ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# expose memcached port
EXPOSE 8080
docker build ./ -t myjenkins
二、运行镜像
docker run -d -p 8888:8080 --name jenkins --restart=always -v /home/jenkins_home:/var/jenkins_home -v /etc/localtime:/etc/localtime myjenkins
三、插件下载
Maven Integration 生成maven项目
四、配置
系统管理-全局工具配置
1、jdk 配置 /opt/jdk1.8.0_181
2、maven配置 /opt/apache-maven-3.5.4
3 、ant配置 /opt/apache-ant-1.10.5
更多推荐
所有评论(0)