ruby 在Docker compose中使用Gem卷中断进行本地依赖更新

xcitsw88  于 12个月前  发布在  Ruby
关注(0)|答案(1)|浏览(64)

当在Docker compose中运行多个ruby服务并共享gem卷时,需要本地扩展的更新将在基础映像更新它们时中断
假设我们有一个这样的docker-compose文件:

(...)
services:
  ruby_service_1:
    (...)
    volumes:
    - gems_volume:/usr/local/bundle
  ruby_service_2:
    (...)
    volumes:
    - gems_volume:/usr/local/bundle
   (...)

这是我在处理多个ruby服务时在很多指南中看到的模式。问题是,当基础镜像更新时(例如,如果你升级了官方ruby镜像的版本),我会得到一个错误,它找不到本地绑定的gem的.so文件。解决方案是删除带有docker compose down --volumes的卷。有没有更好的方法来做到这一点,或者这是你只需要处理时,使用共享卷的宝石?
谢谢,芬恩

h43kikqp

h43kikqp1#

我相信卷的使用在这里对于Ruby bundle来说没有令人印象深刻的优势。Docker隔离的意义已经丧失
也许你不太需要这样的书。但作为选项,您可以为不同的服务定义不同的卷

services:
  ruby_service_1:
    volumes:
      - ruby_service_1_gems:/usr/local/bundle
  ruby_service_2:
    volumes:
      - ruby_service_2_gems:/usr/local/bundle
volumes:
  ruby_service_1_gems: # Define the named volume for ruby_service_1
  ruby_service_2_gems: # Define the named volume for ruby_service_2

通过这种方法,每个服务的gem都是隔离的,从而降低了更新基本Ruby映像时发生冲突的风险

相关问题