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" ]
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
docker build -t jenkins_test:2.190.2 .
docker commit -a jx -m 'jenkins_test' focused_vaughan my_jenkins:test
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: