Circle CI Docker服务不会缓存COPY

前端之家收集整理的这篇文章主要介绍了Circle CI Docker服务不会缓存COPY前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我在CircleCI上运行docker而我在缓存COPY命令时遇到问题.

Circle CI文档提到known caching issues并建议使用this perl script设置复制文件的时间戳以保留缓存.

Docker best practice docs州:

In the case of the ADD and COPY instructions,the contents of the@H_403_11@ file(s) being put into the image are examined. Specifically,a@H_403_11@ checksum is done of the file(s) and then that checksum is used during@H_403_11@ the cache lookup.

根据CircleCi的建议,我将缓存保存到磁盘,然后在下次测试运行时再次加载.这似乎是在COPY高速缓存正确之前的命令.

要调试,我输出我试图在本地复制的文件的md5校验和,然后从docker容器中输出并且它正确匹配.所以,理论上缓存应该加载.我不确定Docker是否使用md5作为校验和.

这是我目前的circle.yml:

机:@H_403_11@  服务:@H_403_11@     – 码头工人

dependencies:
  cache_directories:
    - "~/docker"
  pre:
    - mkdir -p ~/docker
  override:
    - docker info
    - if [[ -e ~/docker/image.tar ]]; then docker load -i ~/docker/image.tar; fi
    - docker images
    - docker build -t circles .

checkout:
  post:
    - ls -l
    - ./timestamp-set-to-git.pl
    - ls -l

test:
  override:
    - md5sum .bowerrc
    - docker run circles md5sum .bowerrc
    - docker save circles > ~/docker/image.tar

这是校验和步骤的构建输出

$md5sum .bowerrc
8d1a712721d735bd41bf738cae3226a2 .bowerrc

$docker run circles md5sum .bowerrc
8d1a712721d735bd41bf738cae3226a2 .bowerrc

但是docker build报告了这个:

Step 6 : RUN sudo npm install -g phantomjs gulp
 ---> Using cache
 ---> a7bbf2b17977
Step 7 : COPY .bowerrc /var/work/.bowerrc
 ---> 7ad82336de64

有谁知道为什么COPY不缓存?

最佳答案
Docker使用TARSUM来决定是否使用Cache,这包括文件元数据.修改时间最重要的是…运行git clone将迫使它从头开始重建.

解决这个问题,我使用带有以下目标的Makefile …

build: hack-touch
    docker build -t MYTAG .
hack-touch:
    @echo "Reset timestamps on git working directory files..."
    find conf | xargs touch -t 200001010000.00
    touch -t 200001010000.00 Gruntfile.js bower.json package.json .bowerrc

(在我的例子中,我想要缓存的所有内容,例如requirements.txt文件都在conf中,除了第二行的Gruntfile内容.我想要缓存的实际源代码都没有)

原文链接:https://www.f2er.com/docker/436839.html

猜你在找的Docker相关文章