找不到/home/rails/webapp/Gemfile.lock所需的“ bundler”(2.1.4)。 (Gem :: GemNotFoundException)运行docker build

时间:2020-06-05 04:37:42

标签: ruby-on-rails docker rubygems bundler

每当我尝试运行docker build -t ruby-app .时,我就一直遇到此问题,出现以下错误:

Step 6/8 : RUN bundle install
 ---> Running in daa149748210
/usr/local/lib/ruby/2.6.0/rubygems.rb:283:in `find_spec_for_exe': Could not find 'bundler' (2.1.4) required by your /home/rails/webapp/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:2.1.4`
        from /usr/local/lib/ruby/2.6.0/rubygems.rb:302:in `activate_bin_path'
        from /usr/local/bin/bundle:23:in `<main>'
The command '/bin/sh -c bundle install' returned a non-zero code: 1

我的Dockerfile如下:

#Dockerfile    
FROM ruby:latest
ENV HOME /home/rails/webapp
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
WORKDIR $HOME
ADD Gemfile* $HOME/
RUN bundle install
ADD . $HOME
CMD ["rails", "server", "--binding", "0.0.0.0"]

我的计算机上安装的捆绑软件版本如下:

➜ gem list bundler          

*** LOCAL GEMS ***

bundler (2.1.4)
bundler-unload (1.0.2)
rubygems-bundler (1.4.5)

我的Gemfile.lock由以下版本的Ruby和Bundler生成

#Gemfile.lock    
RUBY VERSION
ruby 2.7.0p0

BUNDLED WITH
2.1.4

任何帮助将不胜感激!

2 个答案:

答案 0 :(得分:9)

添加

RUN gem install bundler

在调用bundler之前,这应该可以解决问题。

答案 1 :(得分:0)

在调用之前运行 sudo gem install bundler:2.1.2 -n /usr/local/bin