gpt4 book ai didi

ruby-on-rails - 在Docker上对ruby进行 bundle 优化

转载 作者:行者123 更新时间:2023-12-02 21:29:08 24 4
gpt4 key购买 nike

我是Docker的新手,想知道ruby bundler在重新构建docker镜像时如何表现?第一次构建镜像时,它永远需要bundle install。当我在Gemfile中添加另一个gem时会发生什么?有没有办法确保以前的 gem 以某种方式缓存在图像中并用于新的 bundle ?

Dockerfile:

FROM rails:onbuild
RUN apt-get install -y imagemagick

最佳答案

这取决于您如何对Gemfile进行ADD

ADD Gemfile /var/www/yourapp/
ADD Gemfile.lock /var/www/yourapp/
RUN bundle install

在这种情况下, bundle install仅在 GemfileGemfile.lock更改时才运行。请注意,此指令在Dockerfile中的位置很重要。一旦先前的构建步骤缓存无效,所有后续指令将不再被缓存。 (例如,您在 ADD之前 Gemfile一个配置文件,并且更改后的-> bundle install将运行)。

What will happen when I add another gem into the Gemfile?



如果您只想添加几个 gem 而不 bundle 所有内容,则还可以执行以下操作:
ADD Gemfile /var/www/yourapp/
ADD Gemfile.lock /var/www/yourapp/
RUN bundle install
...
ADD Gemfile.tip /var/www/yourapp/
RUN bundle install

Here is a rails example project you can check out (well documented).

关于ruby-on-rails - 在Docker上对ruby进行 bundle 优化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28027173/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com