How Do I Persist Cache With Docker? #36935
-
Hi, I'm trying to persist Nextjs cache across rebuilds of my docker container. I have added the line Could anyone please offer any advice on how to achieve a persistent cache? Update, I Have also tried with |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
I found the answer, this is what I needed:
|
Beta Was this translation helpful? Give feedback.
-
If you use VOLUME ["/app/.next/cache"] in your Dockerfile, anytime a new container is created, it will create a new volume. docker run --name nextjs -d |
Beta Was this translation helpful? Give feedback.
-
Updated Sep 18 2024, if you do it like in my previous comment, i.e. mounting the whole .next folder, it will cache everything. If you add any changes to the codebase and deploy a new container, it will serve the old cached version of a page from the mounted volume. I fixed this problem by only mounting the Images folder in the .next folder. docker stop nextjs && |
Beta Was this translation helpful? Give feedback.
I found the answer, this is what I needed: