Home  >  Q&A  >  body text

docker-images - Dockerfile生成镜像的时候是如何缓存的?

比如我安装一个东西耗时两个小时,但是构建成功之后再构建一次他就很快了,说明它缓存了,现在我的疑惑是如果我稍微改变了一点东西,如何保证他不需要在再耗时两个小时。

大家讲道理大家讲道理2760 days ago761

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-04-22 09:02:35

    Every time a RUN command is executed during the docker build process, an image is generated. In addition, the images are related by blood. Whether it takes two hours to recompile depends on how early the first image affected by your modification is.
    Simple understanding when you modify dockerfile, when you modify 第N行的RUN命令, N+1之后的命令都要重跑;

    docker image --tree #查看镜像的依赖关系
    
    另外你直接docker images也能看到很多None名字的镜像文件,
    那就是你之前build的结果; 如果build成功的话,就会把None改成你指定的name;

    reply
    0
  • Cancelreply