Search code examples
ruby-on-railsdockerdocker-composebundleramazon-ecs

Docker Compose Version 3: Cache gems to speed up run-time bundle install


Before I begin: This is not a post about speeding up bundle install that runs when I build the container.

I am building a Docker application that needs to run bundle install during runtime. It may take a while to explain this specific use-case, but the important component is: my running container will download rails projects, and run bundle install. Currently, this takes an extremely long time (likely because of nokogiri).

Is there a way to build my container, such that anytime my script runs bundle install during runtime, it uses cached gems?

I am using: Docker Compose Version 3 Fargate ECS


Solution

    1. Set your BUNDLE_PATH env var to vendor/bundle
    2. Mount a volume in Fargate to the bundle path

    The first run will be slow since it has to build up the bundle cache, but after that it should only update gems if necessary.