Example of caching the entire state of docker in /var/lib/docker
in order to maintain the cache
from a RUN --mount=type=cache
command.
The relevant source is in .github.
Note that if /var/lib.docker
is big at the end of your build then this is a pretty slow solution,
somewhat defeating the objective of a cache! In a real world situation:
- running the
actions/cache@v2
to download the 1.6GB tar ball representing/var/lib/docker
takes 38 seconds - untarring it takes a further 13 seconds
- starting docker up again takes 5 seconds
So all told it takes 56 seconds to get docker up and running with the restored /var/lib/docker
.
In addition, creating the tar ball at the end of the build takes 15 seconds & uploading it to
wherever actions/cache@v2
puts it a further 45 seconds, so that's another minute at the end of
your build.
In a real world example this still represents a saving of nearly 2 minutes, so can have value. See:
- Cached build: 4m 42s
- Uncached build: 6m 38s (excluding the 1m 43s which is cache creation related)
See stackoverflow: How do I reuse the cache from a RUN --mount=type=cache
docker build?
for more context.
May be made redundant when/if buildkit #1512 Allow controlling cache mounts storage location is done.