How can I prevent a Dockerfile instruction from being cached?

后端 未结 3 1636
無奈伤痛
無奈伤痛 2020-12-14 00:51

In my Dockerfile I use curl or ADD to download the latest version of an archive like:

FROM debian:jessie
...
RUN apt-g         


        
3条回答
  •  醉酒成梦
    2020-12-14 01:12

    docker build --no-cache would invalidate the cache for all the commands.

    Dockerfile ADD command used to have the cache invalidated. Although it has been improved in recent docker version:

    Docker is supposed to checksum any file added through ADDand then decide if it should use the cache or not.

    So if the file added has changed, the cache should be invalidated for the ADD command.


    Issue 1326 mentions other tips:

    This worked.

    RUN yum -y install firefox #redo
    

    So it looks like Docker will re-run the step (and all the steps below it) if the string I am passing to RUN command changes in anyway - even it's just a comment.

    The docker cache is used only, and only if none of his ancestor has changed (this behavior makes sense, as the next command will add change to the previous layer).

    The cache is used if there isn't any character which has changed (so even a space is enough to invalidate a cache).

提交回复
热议问题