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 ...

Get Docker for Rails Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.