• Dockerfile自建jenkins镜像


    Dockerfile

    FROM centos:centos7
    
    WORKDIR /etc/yum.repos.d
    
    RUN mkdir bak && mv ./*.repo bak/; \
        curl -o CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo; \
        sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo; \
        yum -y install epel-release.noarch bash-completion net-tools wget unzip  git freetype fontconfig; \
        mkdir /root/jenkins
    
    WORKDIR /usr/local/
    
    ADD ./apache-maven-3.9.5-bin.zip ./
    ADD ./apache-ant-1.10.14-bin.tar.gz ./
    ADD ./jdk-8u212-linux-x64.tar.gz ./
    
    RUN unzip apache-maven-3.9.5-bin.zip
    
    
    ENV MAVEN_HOME=/usr/local/apache-maven-3.9.5 \
        JAVA_HOME=/usr/local/jdk1.8.0_212 \
        CLASSPATH=$:CLASSPATH:$JAVA_HOME/lib/ \
        ANT_HOME=/usr/local/apache-ant-1.10.14 \
        PATH=${MAVEN_HOME}/bin:${ANT_HOME}/bin:${JAVA_HOME}/bin:${PATH}
    
    RUN echo 'export PATH="${MAVEN_HOME}/bin:${ANT_HOME}/bin:${JAVA_HOME}/bin:${PATH}"' >> ~/.bashrc
    
    
    WORKDIR /root/jenkins
    
    COPY ./jenkins.war ./ 
    COPY ./jenkins.sh  ./
    COPY ./checkstyle-10.12.4-all.jar ./
    COPY ./change_file/myConf.tar ./
    COPY ./change_file/plugins.tar ./
    COPY ./change_file/tools.tar ./
    
    EXPOSE 8080
    ENTRYPOINT [ "/bin/bash", "/root/jenkins/jenkins.sh" ]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39

    jenkins.sh

    #!/bin/bash
    source /root/.bashrc
    cd /root/jenkins && nohup java -jar -Dhudson.security.csrf.GlobalCrumbIssuerConfiguration.DISABLE_CSRF_PROTECTION=true ./jenkins.war  &
    sleep 5
    pkill java 
    
    tar -xf myConf.tar -C /root/.jenkins/
    tar -xf plugins.tar -C /root/.jenkins/
    tar -xf tools.tar -C /root/.jenkins/
    
    java -jar -Dhudson.security.csrf.GlobalCrumbIssuerConfiguration.DISABLE_CSRF_PROTECTION=true ./jenkins.war
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    docker build -t jenkins_test:2.190.2 .
    docker commit -a jx -m 'jenkins_test' focused_vaughan my_jenkins:test
    
    • 1
    • 2

    docker-compose.yml

    version: '3'
    services:
      jenkins:
        user: root
        restart: always
        image: devops_jenkins:2.190.2
        hostname: jenkins
        privileged: true
        container_name: jenkins
        networks:
          - jenkins
        environment:
          - LANG=en_US.utf8
          - TZ=Asia/Shanghai
        ports:
          - 8088:8080
          - 50000:50000
        volumes:
          - jenkins_home:/root/.jenkins
          - mvn_repository:/root/.m2/repository
          - mvn_conf:/usr/local/apache-maven-3.9.5/conf
        logging:
            options:
              max-size: "128M"
              max-file: "1"
        healthcheck:
             test: ["CMD","curl","-s","-f","http://localhost:50000"]
             interval: 30s
             timeout: 10s
             retries: 10
    networks:
      jenkins:
    volumes:
      jenkins_home:
      mvn_repository:
      mvn_conf:
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
  • 相关阅读:
    码农创造了AI,但开发AI不再需要码农了
    cmd命令跳转至指定目录
    【CV】第 16 章:结合计算机视觉和强化学习
    aop实现动态日志
    Java基础进阶-序列化
    哈佛积极心理学
    安卓绘制原理之 MeasureCache优化了什么?
    web前端期末大作业 基于HTML+CSS+JavaScript程序员个人博客模板(web学生作业源码)
    全网最详细:基于SpringMVC实现CRUD&文件上传下载
    国产化Kettle、JDK、MySQL下载安装操作步骤
  • 原文地址:https://blog.csdn.net/weixin_47297088/article/details/134059371