Here is my docker file for the same file, in accordance with the number of the number of layer layers were constructed two mirrored jenkins-master. Both the size difference is 300MB.
<1> layer too many layers, the command will not merge into one command
FROM jenkins/jenkins:2.194 MAINTAINER [email protected] USER root ENV MAVEN_HOME /usr/local/maven ENV JAVA_HOME /usr/local/java ENV M2=/usr/local/maven/repository ENV CLASSPATH .:$JAVA_HOME/lib:$M2_HOME/lib ENV PATH $MAVEN_HOME/bin:$JAVA_HOME/bin:$PATH RUN mkdir -p /usr/local/java RUN mkdir -p /usr/local/maven/repository COPY soft/apache-maven-3.5.4/* /usr/local/ COPY soft/jre1.8.0_212/* /usr/local/java/
<2> layer layers rarely, all commands combined into one command
FROM jenkins/jenkins:2.194 MAINTAINER [email protected] USER root && \ ENV MAVEN_HOME /usr/local/maven && \ ENV JAVA_HOME /usr/local/java && \ ENV M2 /usr/local/maven/repository && \ ENV CLASSPATH .:$JAVA_HOME/lib:$M2_HOME/lib && \ ENV PATH $MAVEN_HOME/bin:$JAVA_HOME/bin:$PATH && \ RUN mkdir -p /usr/local/java && \ RUN mkdir -p /usr/local/maven/repository && \ COPY soft/apache-maven-3.5.4/* /usr/local/ && \ COPY soft/jre1.8.0_212/* /usr/local/java/
Then, each build command execution
root >> cd /opt/dockerfile/jenkins/02/
root >> docker build -f /opt/dockerfile/jenkins/02/jenkins-master-01.Dockerfile . -t registry.cn-hangzhou.aliyuncs.com/kevin_docker_registry/mirror_k8s_jenkins-master:2.194
root >> docker build -f /opt/dockerfile/jenkins/02/jenkins-master-02.Dockerfile . -t registry.cn-hangzhou.aliyuncs.com/kevin_docker_registry/mirror_k8s_jenkins-master:2.194-test
Finally, we test results
I found the second dockerfile generated image file size smaller than the former volume of 300MB.
root >> docker images
appendix:
If required, we can also generate good jenkins-master submit to Ali cloud storage, refer to the following command
After uploading, log Ali cloud storage, to view mirror version follows
Reference material
https://www.cnblogs.com/ericnie/p/7991218.html