为什么我的 Docker 缓存被这个 COPY 命令弄坏了?



我在 CI 系统中的 docker 构建器在不活动后被销毁,从而丢失本地缓存。我首先 quay.io 从存储库中提取最新的映像,然后在下一个构建中将其用作--cache-from,从而使用--cache-from。 我正在运行码头工人版本17.12.0-ce. Dockerfile(相关部分)看起来像:

FROM ubuntu:16.04
RUN apt-get update && apt-get install -y 
ant 
build-essential 
software-properties-common 
libncurses5-dev 
libncursesw5-dev 
libcurl4-openssl-dev 
libboost-dev 
libfreetype6-dev 
zlib1g-dev 
r-base 
default-jdk 
python-dev 
python-setuptools 
python-pip 
python3-dev 
python3-setuptools 
python3-pip 
git 
wget 
unzip 
ghostscript 
pkg-config

RUN mkdir /software
WORKDIR /software
ENV PATH="/software:${PATH}"
RUN git clone --branch v0.2.19 --single-branch 
https://github.com/xianyi/OpenBLAS
RUN cd OpenBLAS && make FC=gfortran TARGET=NEHALEM USE_THREAD=0 && make 
PREFIX=/opt/openblas install
ENV LD_LIBRARY_PATH="/opt/openblas/lib:${LD_LIBRARY_PATH}"
# Install samtools dependencies
RUN wget http://zlib.net/zlib-1.2.11.tar.gz && tar -xvf zlib-1.2.11.tar.gz
RUN cd zlib-1.2.11 && ./configure && make && make install
RUN wget http://bzip.org/1.0.6/bzip2-1.0.6.tar.gz && tar -xvf bzip2-
1.0.6.tar.gz
RUN cd bzip2-1.0.6 && make && make install
RUN wget https://tukaani.org/xz/xz-5.2.3.tar.gz && tar -xvf xz-5.2.3.tar.gz
RUN cd xz-5.2.3 && ./configure && make && make install
RUN pip install common python-dateutil cython
RUN pip3 install common python-dateutil cython
# Install numpy 1.11.3 (python2/3)
RUN git clone --branch v1.11.3 --single-branch https://github.com/numpy/numpy
COPY /docker_image/site.cfg numpy/
RUN cd numpy && python setup.py install
RUN cd numpy && python3 setup.py install

当我使用(干净的机器,缓存中没有任何内容)运行我的构建时:

docker pull quay.io/myorganization/myimage:tag

然后运行构建

docker build --cache-from=quay.io/myorganization/myimage:tag -f docker_image/Dockerfile -t quay.io/myorganization/myimage:newtag .

生成将使用缓存,直到COPY /docker_image/site.cfg numpy/使缓存失效。我的 .dockerignore 看起来像:

.git*

所以那里的事情变化不应该是问题。如果我不小心遗漏了一些需要的重要信息,请询问,我会及时提供。任何关于可能导致此特定位置缓存失效的想法将不胜感激。

编辑:即使我不在构建之间更改存储库中的任何内容,也会发生此缓存失效,方法是执行以下操作:使用 tag1 构建映像,推送映像 quay.io,然后在干净的计算机上克隆 git 存储库、拉取映像 (tag1)、使用 tag2 构建映像。可能是 numpy 存储库元数据发生变化吗?(注意:据我了解,单分支不应提取有关该存储库中其他分支的任何信息)。

COPYADD命令的 docker 缓存使用文件和目录的哈希。该哈希中包括每个文件的内容,甚至是文件的权限。因此,如果其中任何一个更改了一个字节,则哈希将不同,并且 docker 将出现缓存未命中,从而强制重新运行该行。

从第一次缓存未命中开始,所有剩余的行都需要重建,因为前一层现在是新的,尚未用于运行以下任何步骤。

最新更新