Docker build is not using cache

后端 未结 1 1768
心在旅途
心在旅途 2021-02-01 04:56

docker build is not using it\'s cache.

docker build -f Dockerfile .

generates the same output that this does:

doc         


        
相关标签:
1条回答
  • 2021-02-01 05:31

    From your Dockerfile, if you append lines to your Dockerfile, or change the code being built, there's only one line that could be cached:

    RUN mkdir /code
    

    After that, you perform a:

    COPY . /code
    

    Since you have changed your Dockerfile, the contents of . have changed (the Dockerfile is part of .) and therefore the COPY needs to be performed again, generating a new layer. Once you generate a new layer, every following layer no longer has a cache and needs to be rebuild.

    To improve caching, consider placing the lines that change less towards the top of your Dockerfile. That would leave the COPY . /code line at the very end of the file since it will change almost every time.

    0 讨论(0)
提交回复
热议问题