App spec does not use Docker container caching

The only thing I changed in my App Spec file is database username. Yet it triggered full rebuild of the Docker, which takes around 10 minutes for 1 service + 10 minutes for a job (both using the same Dockerfile).

There are two issues here:

Issue 1. Docker build cache is not used.

Issue 2. Docker build result is not shared between the job and the service.

This makes me wait for 20 minutes every time I experiment with the App spec, even though there is nothing that would indicate the need to rebuild from scratch:

  • no build time args changes
  • no Dockerfile changes

Is this expected behavior?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

@ReWild 👋

Thanks for surfacing this — it’s not intended behavior. This is related to the job component specifically, where we were not excluding some of the non-build context from the reuse keys. We’ve deployed a fix for this, and is working as expected now. Let us know if you hit any more problems or if it’s not completely resolved for you.

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.