How can I prevent a Dockerfile instruction from being cached?

后端 未结 3 1638
無奈伤痛
無奈伤痛 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 00:54

    A build-time argument can be specified to forcibly break the cache from that step onwards. For example, in your Dockerfile, put

    ARG CACHE_DATE=not_a_date
    

    and then give this argument a fresh value on every new build. The best, of course, is the timestamp.

    docker build --build-arg CACHE_DATE=$(date +%Y-%m-%d:%H:%M:%S) ...
    

    Make sure the value is a string without any spaces, otherwise docker client will falsely take it as multiple arguments.

    See a detailed discussion on Issue 22832.

提交回复
热议问题