Ruby on rails Docker Compose和Rails:Bundler::GemNotFound启动时。bundler没有看到正确的宝石吗?
我正试图按照说明使用Docker Compose设置Rails和Postgres应用程序,如文档中所述-> 但是,在成功设置数据库后,当我尝试启动应用程序时,在运行Ruby on rails Docker Compose和Rails:Bundler::GemNotFound启动时。bundler没有看到正确的宝石吗?,ruby-on-rails,docker,docker-compose,bundler,Ruby On Rails,Docker,Docker Compose,Bundler,我正试图按照说明使用Docker Compose设置Rails和Postgres应用程序,如文档中所述-> 但是,在成功设置数据库后,当我尝试启动应用程序时,在运行docker compose up时遇到以下错误: docker-compose up Creating docker-and-cms_db_1 ... done Creating docker-and-cms_web_1 ... done Attaching to docker-and-cms_db_1, docker-and-cm
docker compose up
时遇到以下错误:
docker-compose up
Creating docker-and-cms_db_1 ... done
Creating docker-and-cms_web_1 ... done
Attaching to docker-and-cms_db_1, docker-and-cms_web_1
web_1 | bundler: failed to load command: rails (/usr/local/bundle/bin/rails)
web_1 | Bundler::GemNotFound: Could not find bindex-0.8.1 in any of the sources
web_1 | /usr/local/lib/ruby/2.6.0/bundler/spec_set.rb:91:in `block in materialize'
web_1 | /usr/local/lib/ruby/2.6.0/bundler/spec_set.rb:85:in `map!'
web_1 | /usr/local/lib/ruby/2.6.0/bundler/spec_set.rb:85:in `materialize'
web_1 | /usr/local/lib/ruby/2.6.0/bundler/definition.rb:170:in `specs'
web_1 | /usr/local/lib/ruby/2.6.0/bundler/definition.rb:237:in `specs_for'
web_1 | /usr/local/lib/ruby/2.6.0/bundler/definition.rb:226:in `requested_specs'
web_1 | /usr/local/lib/ruby/2.6.0/bundler/runtime.rb:108:in `block in definition_method'
web_1 | /usr/local/lib/ruby/2.6.0/bundler/runtime.rb:20:in `setup'
web_1 | /usr/local/lib/ruby/2.6.0/bundler.rb:107:in `setup'
web_1 | /usr/local/lib/ruby/2.6.0/bundler/setup.rb:20:in `<top (required)>'
web_1 | /usr/local/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
web_1 | /usr/local/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
docker-and-cms_web_1 exited with code 1
这是我的entrypoind.sh
# From https://docs.docker.com/compose/rails/
FROM ruby:2.6.5
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client
RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle install --path vendor/cache
COPY . /myapp
# Add a script to be executed every time the container starts.
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000
# Start the main process.
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]
#!/bin/bash
set -e
# Remove a potentially pre-existing server.pid for Rails.
rm -f /myapp/tmp/pids/server.pid
# Then exec the container's main process (what's set as CMD in the Dockerfile).
exec "$@"
最后是我的docker compose.yml
文件
version: '3'
services:
db:
image: postgres
volumes:
- ./tmp/db:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: password
web:
build: .
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
volumes:
- .:/myapp
ports:
- "3000:3000"
depends_on:
- db
这是我的Gemfile
的开头(经过编辑,因为我认为只有前几行是相关的):
谢谢你的帮助 在Docker容器中,Bundler正在错误的目录中查找gem,如您所说。当容器启动时,Bundler安装并找到Ruby 2.6.0,或者,将某些内容复制到容器中,使Bundler相信已安装Ruby 2.6.0 当您使用Docker image ruby:2.5.6时,上面的第二个选项更可能出现 如果查看Docker文件的第8-9行,您将看到在构建Docker映像时,Gemfile和Gemfile.lock从本地计算机复制到容器中 我认为这里可能发生的事情是,在本地机器上生成的Gemfile.lock是使用Ruby 2.6.0完成的 您的本地机器(不在容器中)的Ruby版本是什么?运行
ruby-v
查看
尝试在本地计算机上安装Ruby 2.6.5并运行bundle install
,以更新Gemfile.lock
我在手机上,目前自己无法测试这些。但这是一个开始 谢谢你的帮助!我本地机器上的ruby版本是ruby 2.6.3p62。并不是说我以前在本地机器上使用rvm来管理我的Ruby版本。由于到目前为止它是一个空项目,我将尝试删除我的Gemfile.lock。注意,Gemfile.lock似乎是用ruby 2.6.5生成的(在这里复制文件的结尾)。RUBY版本RUBY 2.6.5p114与1.17.2I捆绑在一起,我编辑了这个问题,添加了来自容器的bundle env结果。看看这个(很旧)
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.6.5'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.4', '>= 5.2.4.1'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# (...)
root@588227887e16:/myapp# bundle env
## Environment
Bundler 1.17.2
Platforms ruby, x86_64-linux
Ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux]
Full Path /usr/local/bin/ruby
Config Dir /usr/local/etc
RubyGems 3.0.3
Gem Home /usr/local/bundle
Gem Path /root/.gem/ruby/2.6.0:/usr/local/lib/ruby/gems/2.6.0:/usr/local/bundle
User Path /root/.gem/ruby/2.6.0
Bin Dir /usr/local/bundle/bin
Tools
Git 2.20.1
RVM not installed
rbenv not installed
chruby not installed
## Bundler Build Metadata
Built At 2018-12-19
Git SHA 3fc4de72b
Released Version false
## Bundler settings
path
Set for your local app (/usr/local/bundle/config): "vendor/cache"
app_config
Set via BUNDLE_APP_CONFIG: "/usr/local/bundle"
silence_root_warning
Set via BUNDLE_SILENCE_ROOT_WARNING: true