下载openjdk, maven 等到目录中。
#Dockerfile
FROM jenkins/jenkins:lts-centos
ENV JDK=openjdk-13.0.2_linux-x64_bin.tar.gz
ENV MAVEN=apache-maven-3.6.3-bin.tar.gz
# copy the jdk archive to the image,and it will automaticlly unzip the tar file
ADD ${JDK} /opt/
ADD ${MAVEN} /opt/
ADD hudson.model.UpdateCenter.xml /var/jenkins_home/hudson.model.UpdateCenter.xml
# use root
USER root
创建hudson.model.UpdateCenter.xml 。国内或许需要此文件,解决有可能会第一次启动jenkins很慢很慢。
<?xml version='1.1' encoding='UTF-8'?>
<sites>
<site>
<id>default</id>
<url>http://mirror.xmission.com/jenkins/updates/update-center.json</url>
</site>
</sites>
build jenkins 自定义镜像
docker build . -t my/jenkins
开启自定义的jenkins, 把本机的docker暴露给容器
docker run -d \
--name jenkins-docker \
-p8080:8080 \
--privileged \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /bin/docker:/bin/docker \
-v /usr/local/bin/docker-compose:/bin/docker-compose \
my/jenkins
如需要jenkins的镜像加速,进入jenkins容器中。参考 https://my.oschina.net/u/160697/blog/3168774
echo "127.0.0.1 mirrors.jenkins-ci.org" >> /etc/hosts
来源:oschina
链接:https://my.oschina.net/u/160697/blog/3171515