Disable cache for specific RUN commands

前端 未结 7 524
暗喜
暗喜 2020-11-30 05:16

I have a few RUN commands in my Dockerfile that I would like to run with -no-cache each time I build a Docker image.

I understand the

7条回答
  •  遥遥无期
    2020-11-30 05:53

    I believe that this is a slight improvement on @steve's answer, above:

    RUN git clone https://sdk.ghwl;erjnv;wekrv;qlk@gitlab.com/your_name/your_repository.git
    
    WORKDIR your_repository
    
    # Calls for a random number to break the cahing of the git clone
    # (https://stackoverflow.com/questions/35134713/disable-cache-for-specific-run-commands/58801213#58801213)
    ADD "https://www.random.org/cgi-bin/randbyte?nbytes=10&format=h" skipcache
    RUN git pull
    

    This uses the Docker cache of the git clone, but then runs an uncached update of the repository.

    It appears to work, and it is faster - but many thanks to @steve for providing the underlying principles.

提交回复
热议问题