Rob Yurkowski

  • About Me
  • Services
  • Work With Me
  • Blog
  • Mounting a Local Gem in Docker Compose

    Mount a gem into a docker container with path/on/disk/gemdir:/app/path/vendor/gems/my_gem and then set your Gemfile to gem "my_gem", path: "vendor/gems/my_gem".

    Make this less irritating to manage when committing by adding a method for your Gemfile, e.g.:

    def local_gem_exists?(name)
      File.directory?("vendor/gems/#{name}")
    end
    
    def maybe_local_gem(name, env: ENV.fetch("RACK_ENV", production), **opts)
      return gem name, **opts if env == "production" || !local_gem_exists?
      
      gem name, opts.merge(path: "vendor/gems/#{name}")
    end
    
    # and use like:
    
    maybe_local_gem "my_gem" # if you've mounted the gem, loads from path, otherwise declares remote gem
    

    You could also consider overriding gem().