You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MacBook M1环境下Rails容器可构建但无法启动问题

Rails容器构建成功但启动失败:Bundler版本找不到问题解决

问题描述

容器可正常构建,但启动时抛出以下错误:

Activating bundler (~> 2.3) failed:
Could not find 'bundler' (2.3.18) required by $BUNDLER_VERSION.
To update to the latest version installed on your system, run bundle update --bundler.
To install the missing version, run gem install bundler:2.3.18
Checked in 'GEM_PATH=/root/.gem/ruby/2.5.0:/usr/local/lib/ruby/gems/2.5.0:/usr/local/bundle' , execute gem env for more information

To install the version of bundler this project requires, run gem install bundler -v '~> 2.3'

当前Dockerfile相关配置:

FROM --platform=linux/amd64 ruby:2.5.9-slim-stretch

(...)

ENV BUNDLER_VERSION 2.3.18
RUN gem update --system 3.2.3
RUN gem install bundler -v "$BUNDLER_VERSION" 

解决思路

  • 检查Bundler安装路径与GEM_PATH匹配
    进入容器执行gem env,确认bundler 2.3.18是否安装在报错提示的GEM_PATH目录中。若路径不匹配,可在安装时指定目录:

    RUN gem install bundler -v "$BUNDLER_VERSION" --install-dir /usr/local/bundle
    
  • 确保启动阶段Bundler版本生效
    若构建阶段设置的环境变量在启动时被覆盖,可在启动命令中显式指定Bundler版本:

    bundle _2.3.18_ exec rails server
    
  • 清理Gem缓存避免版本冲突
    在Dockerfile中添加缓存清理步骤,消除缓存导致的版本不一致:

    ENV BUNDLER_VERSION 2.3.18
    RUN gem update --system 3.2.3 && \
        gem install bundler -v "$BUNDLER_VERSION" && \
        rm -rf /usr/local/bundle/cache/*.gem && \
        rm -rf /root/.gem
    
  • 尝试跳过RubyGems系统更新
    若gem update --system导致环境异常,可直接安装指定版本的Bundler:

    ENV BUNDLER_VERSION 2.3.18
    RUN gem install bundler -v "$BUNDLER_VERSION"
    

内容的提问来源于stack exchange,提问作者Daniel Belarmino

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 23:33:14