docker / roadmap

Welcome to the Public Roadmap for All Things Docker! We welcome your ideas.
https://github.com/docker/roadmap/projects/1
Creative Commons Zero v1.0 Universal
1.45k stars 244 forks source link

Invalidate cache based on the exit code of a command #628

Open limwz01 opened 2 months ago

limwz01 commented 2 months ago

Tell us about your request I would like to have a new command in Dockerfile (let's say it's called VALIDATE_CACHE), which is attached to a previous RUN command. If the previous RUN was cached, docker would run the command specified in a temporary layer to validate the cached image and if the result is SUCCESS it would discard the layer and continue, otherwise it would rerun the previous RUN without cache. This is useful to implement a cached package repository update command like apt update for Debian/Ubuntu. For example:

RUN apt update
VALIDATE_CACHE apt update | $(! grep -q Fetched)

A more elaborate method can be used to only invalidate the cache when specified packages are upgraded.

Which service(s) is this request for? Docker

Tell us about the problem you're trying to solve. What are you trying to do, and why is it hard? Currently, either the apt update will be cached and later apt get will use an outdated cache or it takes quite long to run apt update every time.

Are you currently working around the issue? Best workaround so far is to have apt update && before every apt get command, but this wouldn't upgrade packages automatically.

Additional context N/A