-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using --mount=type=cache means the cache is not available at runtime #2147
Comments
I was forwarded to the following thread today: #1512 |
|
FWIW, ran into this issue and found a semi-working solution. npm has a cache directory for installs that is different than You can specify this location Use that as the target, and then you can cache the npm cache and not the node_modules which is your actual installed dependencies. To make it even better you can split stages and copy the node_modules from the builder stage. Add This means the cache worked.
The multi stage here is not super useful, but if you needed to do more things in each layer the benefits compound.
|
I am actually using a different language and toolchain, but here is a simple illustration of the problem.
My dockerfile:
This can be built into an image and a container, but when I try to execute commands in the container, the cache is not there.
node_modules
exists, but is empty. I must reinstall it every time I wish to enter the container and execute a one-off command.I'm actually not trying to cache
node_modules
nor use JavaScript at all, but what I'm doing operates largely the same way as yarn's cache. I'm trying to cache the equivalent of/home/user/.cache/yarn/v6
, so that I can try to run offline installs.I'm having this issue with haskell's cabal-install, and the process takes several minutes to complete. In any case, these build tools' caches are apparently permanently discarded after the image is built; and if I run install (even when
node_modules
equivalent is populated) it tries to repopulate the cache.If I remove the
--mount=type=cache
directive, it speeds up the execution of commands on the container by keeping a copy of the generated files. If I keep the--mount
directive, it speeds up the image build just a little bit, but I have to download and repopulate the cache over and over again after the image has been built; and I need to be able to go into a container, tweak a few things, and then run reinstall. I would really like a way to keep the cache around (read-only is fine) at runtime, or to allow the build to write to a volume at build time, so I can manage the cache myself. LikeDOCKER_BUILDKIT=1 docker run --mount=type=cache,etc
.The text was updated successfully, but these errors were encountered: