从特定步骤重建Docker映像

从特定步骤重建Docker映像,第1张

从特定步骤重建Docker映像

您可以通过执行以下 *** 作来重建整个内容,而无需使用缓存

docker build --no-cache -t user/image-name

要强制从特定行开始重新运行,可以传递一个未使用的arg。Docker将ARG值作为环境变量传递给RUN命令,因此更改ARG就是对命令的更改,这会中断缓存。甚至不必在RUN行上自己定义它。

FROM ubuntu:14.04MAINTAINER Samuel Alexander <samuel@alexander.com>RUN apt-get -y install software-properties-commonRUN apt-get -y update# Install Java.RUN echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | debconf-set-selectionsRUN add-apt-repository -y ppa:webupd8team/javaRUN apt-get -y updateRUN apt-get install -y oracle-java8-installerRUN rm -rf /var/lib/apt/lists/*RUN rm -rf /var/cache/oracle-jdk8-installer# Define working directory.WORKDIR /work# Define commonly used JAVA_HOME variableENV JAVA_HOME /usr/lib/jvm/java-8-oracle# JAVA PATHENV PATH /usr/lib/jvm/java-8-oracle/bin:$PATH# Install mavenRUN apt-get -y updateRUN apt-get -y install maven# Install Open SSH and gitRUN apt-get -y install openssh-serverRUN apt-get -y install git# clone SparkRUN git clone https://github.com/apache/spark.gitWORKDIR /work/sparkRUN mvn -DskipTests clean package# clone and build zeppelin fork, changing INCUBATOR_VER will break the cache hereARG INCUBATOR_VER=unknownRUN git clone https://github.com/apache/incubator-zeppelin.gitWORKDIR /work/incubator-zeppelinRUN mvn clean package -Pspark-1.6 -Phadoop-2.6 -DskipTests# Install SupervisordRUN apt-get -y install supervisorRUN mkdir -p var/log/supervisor# Configure SupervisordCOPY conf/supervisord.conf /etc/supervisor/conf.d/supervisord.conf# bashRUN sed -i s#/home/git:/bin/false#/home/git:/bin/bash# /etc/passwdEXPOSE 8080 8082CMD ["/usr/bin/supervisord"]

然后使用唯一的arg运行它:

docker build --build-arg INCUBATOR_VER=20160613.2 -t user/image-name .

要在每次构建时更改参数,您可以将时间戳作为arg传递:

docker build --build-arg INCUBATOR_VER=$(date +%Y%m%d-%H%M%S) -t user/image-name .

要么:

docker build --build-arg INCUBATOR_VER=$(date +%s) -t user/image-name .

顺便说一句,我建议进行以下更改以使您的图层更小,

RUN
在下载并安装后,您可以在单个命令上合并清理和删除步骤的内容越多,最终映像就越小。否则,您的图层将包括下载和清理之间的所有中间步骤:

FROM ubuntu:14.04MAINTAINER Samuel Alexander <samuel@alexander.com>RUN DEBIAN_FRonTEND=noninteractive     apt-get -y install software-properties-common &&     apt-get -y update# Install Java.RUN echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | debconf-set-selections &&     add-apt-repository -y ppa:webupd8team/java &&     apt-get -y update &&     DEBIAN_FRonTEND=noninteractive     apt-get install -y oracle-java8-installer &&     apt-get clean &&     rm -rf /var/lib/apt/lists/* &&     rm -rf /var/cache/oracle-jdk8-installer && # Define working directory.WORKDIR /work# Define commonly used JAVA_HOME variableENV JAVA_HOME /usr/lib/jvm/java-8-oracle# JAVA PATHENV PATH /usr/lib/jvm/java-8-oracle/bin:$PATH# Install mavenRUN apt-get -y update &&     DEBIAN_FRonTEND=noninteractive     apt-get -y install       maven       openssh-server       git       supervisor &&     apt-get clean &&     rm -rf /var/lib/apt/lists/*# clone SparkRUN git clone https://github.com/apache/spark.gitWORKDIR /work/sparkRUN mvn -DskipTests clean package# clone and build zeppelin forkARG INCUBATOR_VER=unknownRUN git clone https://github.com/apache/incubator-zeppelin.gitWORKDIR /work/incubator-zeppelinRUN mvn clean package -Pspark-1.6 -Phadoop-2.6 -DskipTests# Configure SupervisordRUN mkdir -p var/log/supervisorCOPY conf/supervisord.conf /etc/supervisor/conf.d/supervisord.conf# bashRUN sed -i s#/home/git:/bin/false#/home/git:/bin/bash# /etc/passwdEXPOSE 8080 8082CMD ["/usr/bin/supervisord"]


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5163165.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-18
下一篇 2022-11-18

发表评论

登录后才能评论

评论列表(0条)

保存