ruby-on-rails - 找不到 gem rails

标签 ruby-on-rails ruby docker rubygems

我正在尝试构建一个 docker 容器,但收到以下错误消息:

Step 8/12 : RUN bundle binstubs bundler --force
 ---> Running in ed94b127974b
Could not find gem 'rails (>= 5.1.5, ~> 5.1)' in any of the gem sources listed
in your Gemfile.
ERROR: Service 'dockerzon' failed to build: The command '/bin/sh -c bundle binstubs bundler --force' returned a non-zero code: 7

我在我的 Gemfile 中尝试了不同版本的 rails,但没有成功!这是我在 Gemfile 中的内容:
source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
# gem 'rails', '4.2.6'
# gem 'rails', '>= 5.1.5'
gem 'rails', '~> 5.1', '>= 5.1.5'
# Use sqlite3 as the database for Active Record
# gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0.7'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 4.1.6'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 1.0.0', group: :doc

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug'
end

group :development do
  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 3.5.1'

  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
end

gem 'pg', '~> 1.0.0'
gem 'redis-rails', '~> 5.0.2'
gem 'sidekiq', '~> 5.1.1'
gem 'puma', '~> 3.11.2'
gem 'rack-timeout', '~> 0.4.2'

这是我的 Dockerfile:
# Use the barebones version of Ruby 2.5
FROM ruby:2.5-slim

# Optionally set a maintainer name to let people know who made this image.

# Install dependencies:
# - build-essential: To ensure certain gems can be compiled
# - nodejs: Compile assets
# - libpq-dev: Communicate with postgres through the postgres gem
RUN apt-get update && apt-get install -qq -y --no-install-recommends \
      build-essential nodejs libpq-dev

# Set an environment variable to store where the app is installed to inside
# of the Docker image. The name matches the project name out of convention only.
ENV INSTALL_PATH /dockerzon
RUN mkdir -p $INSTALL_PATH

# This sets the context of where commands will be ran in and is documented
# on Docker's website extensively.
WORKDIR $INSTALL_PATH

# Ensure gems are cached and only get updated when they change. This will
# drastically increase build times when your gems do not change.
COPY Gemfile Gemfile

# We want binstubs to be available so we can directly call sidekiq and
# potentially other binaries as command overrides without depending on
# bundle exec.
# RUN bundle install --binstubs
RUN bundle binstubs bundler --force

# Copy in the application code from your work station at the current directory
# over to the working directory.
COPY . .

# Provide a dummy DATABASE_URL to Rails so it can pre-compile assets.
RUN bundle exec rake RAILS_ENV=production DATABASE_URL=postgresql://user:pass@127.0.0.1/dbname SECRET_TOKEN=dummytoken assets:precompile

# Ensure the static assets are exposed through a volume so that nginx can read
# in these values later.
VOLUME ["$INSTALL_PATH/public"]

# The default command that gets ran will be to start the Puma server.
CMD bundle exec puma -C config/puma.rb

最佳答案

尝试更新 RubyGems 的版本:

gem update --system

然后将 Gemfile 中的行更改为:
gem 'rails', '~> 5.1.5'

现在运行 bundler 来安装 gems:
bundle install

关于ruby-on-rails - 找不到 gem rails ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49008314/

相关文章:

ruby-on-rails - 包含关联计数的 Activerecord 查询

ruby-on-rails - 无法加载此类文件 - Nokogiri rails

ruby - 断点和irb的结合(REPL)

ruby-on-rails - 如何获取模型实例变量

ruby-on-rails - Capistrano::NoMatchingServersError on deploy:update_code

ruby-on-rails - 如何为 Capistrano 指定单独的应用程序和数据库服务器?

docker - 使用 glusterfs 在 docker swarm 中持久化数据

docker - 创建了Docker镜像,但是使用Java-SDK实例化Hyperledger Fabric中的链码后容器无法启动

javascript - 我如何根据复选框的状态更改另一种已具有自己样式表的媒体类型的 CSS 值?

docker - 如何在 dockerfile 中回答安装问题?