Using a Gem Cache Volume
As we’ve seen, the key problem is that Docker’s image building, akin to building a machine from scratch, is at odds with the caching of gems with Bundler. What if, instead of fighting the image build process, we bypassed it? We’ve already seen how volumes provide persistent file storage that’s separate from the container filesystem; we can use this to solve our thorny problem.
Here’s the gist.
By mounting a volume in the directory where Bundler installs our gems, we can execute Bundler commands to populate and manage the gems on this volume, which effectively becomes a local gem cache. Remember that a mounted volume overlays, and is separate from, the container’s filesystem; its files persist beyond the life cycle of ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access