为什么我的Docker缓存会被这个COPY命令失效?

为什么我的Docker缓存会被这个COPY命令失效?,docker,Docker,CI系统中的docker构建器在不活动后被销毁,从而丢失本地缓存。我正在使用--cache from,首先从quay.io repo中提取最新的图像,然后在下一次构建中将其用作--cache from。 我正在运行docker版本17.12.0-ce。 Dockerfile(针对相关部分)的外观如下所示: FROM ubuntu:16.04 RUN apt-get update && apt-get install -y \ ant \ build-essential \ sof

CI系统中的docker构建器在不活动后被销毁,从而丢失本地缓存。我正在使用
--cache from
,首先从quay.io repo中提取最新的图像,然后在下一次构建中将其用作
--cache from
。 我正在运行docker版本
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
.git*
当我使用(干净的机器,缓存中没有任何内容)运行构建时:

然后使用

docker build --cache-from=quay.io/myorganization/myimage:tag -f docker_image/Dockerfile -t quay.io/myorganization/myimage:newtag .
生成使用缓存,直到
COPY/docker\u image/site.cfg numpy/
使缓存无效。我的.dockrignore看起来像:

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
.git*
因此,情况的变化不应该是问题所在。如果我不小心遗漏了一些需要的重要信息,请询问,我会及时提供。如果您有任何关于在这个特定位置导致缓存失效的想法,我们将不胜感激

编辑:即使我在构建之间的repo中没有更改任何内容,也会发生缓存失效,方法是:使用tag1构建映像,推送映像
到quay.io,然后在干净的机器上克隆git repo,拉取映像(tag1),用tag2构建映像。可能是numpy回购元数据发生了变化吗?(注意:--据我所知,单个分支机构不应提取该回购协议中其他分支机构的任何信息)。

复制或添加命令的docker缓存使用文件和目录的散列。散列中包括每个文件的内容,甚至包括对文件的权限。因此,如果其中任何一个更改了一个字节,散列将不同,docker将有一个缓存未命中,迫使行重新运行


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

中的文件和目录。
在哈希中也被考虑,还是被忽略?@n00b它们被忽略。从不发送到服务器进行散列。