ruby - 为什么 "bundle install --path"工作时 "bundle install"中断?

标签 ruby docker bundler

`require': LoadError: cannot load such file -- mysql2/mysql2 (Sequel::AdapterNotFound)

仅当我使用 bundle install --path 时,我才不断收到上述错误。当我切换到常规 bundle install 时,一切正常。

在用头撞墙几个小时后,我想是时候寻求帮助了。如何让 bundle install --path 正常工作?我认为它与 docker 容器中的 bundle 环境有关?


这个 bundle env 有效:

Environment

    Bundler   1.13.6
    Rubygems  2.6.8
    Ruby      2.3.2p217 (2016-11-15 revision 56796) [x86_64-linux]
    GEM_HOME  /usr/local/bundle
    GEM_PATH
    Git       2.1.4

Bundler settings

    disable_shared_gems
      Set for your local app (/usr/local/bundle/config): "true"
    path
      Set via BUNDLE_PATH: "/usr/local/bundle"
    bin
      Set via BUNDLE_BIN: "/usr/local/bundle/bin"
    silence_root_warning
      Set via BUNDLE_SILENCE_ROOT_WARNING: "1"
    app_config
      Set via BUNDLE_APP_CONFIG: "/usr/local/bundle"
    bin_path
      Set via BUNDLE_BIN_PATH: "/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/exe/bundle"
    gemfile
      Set via BUNDLE_GEMFILE: "/usr/src/app/Gemfile"

这个包 env 不工作:

Environment

    Bundler   1.13.6
    Rubygems  2.6.8
    Ruby      2.3.2p217 (2016-11-15 revision 56796) [x86_64-linux]
    GEM_HOME  /usr/src/app/vendor/bundle/ruby/2.3.0
    GEM_PATH
    Git       2.1.4

Bundler settings

    path
      Set for your local app (/usr/local/bundle/config): "vendor/bundle"
      Set via BUNDLE_PATH: "/usr/local/bundle"
    disable_shared_gems
      Set for your local app (/usr/local/bundle/config): "true"
    bin
      Set via BUNDLE_BIN: "/usr/local/bundle/bin"
    silence_root_warning
      Set via BUNDLE_SILENCE_ROOT_WARNING: "1"
    app_config
      Set via BUNDLE_APP_CONFIG: "/usr/local/bundle"
    bin_path
      Set via BUNDLE_BIN_PATH: "/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/exe/bundle"
    gemfile
      Set via BUNDLE_GEMFILE: "/usr/src/app/Gemfile"

Dockerfile:

FROM ruby:2.3.2
WORKDIR /usr/src/app
COPY Gemfile .
RUN bundle install --path vendor/bundle

docker-compose.yml:

version: "2"
services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - .:/usr/src/app
    links:
      - db
  db:
    image: mysql:5.6
    ports:
      - "3306:3306"
    volumes:
      - ./schema/create_markup.sql:/docker-entrypoint-initdb.d/create_markup.sql
      - db_data:/var/lib/mysql
    environment:
      MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
volumes:
  db_data:

gem 文件:

# frozen_string_literal: true
source "https://rubygems.org"

gem "mysql2"
gem "sequel"

group :test do
  gem "rspec"
end

最佳答案

这是由您的 docker-compose.yml 的以下行引起的:

volumes:
  - .:/usr/src/app

gems 安装在 /usr/src/app/vendor/bundle 下,但是您正在将当前目录安装到 /usr/src/appdocker-compose.yml。所以你看不到图像中的 gem 。

您需要更改包路径或挂载路径。

关于ruby - 为什么 "bundle install --path"工作时 "bundle install"中断?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41695661/

相关文章:

ruby-on-rails - Rails with angular 与 Rails pure(查看性能)

ruby - 了解字节解包

mongodb - 无法启动docker mongodb

node.js - Docker - 从基础镜像中覆盖或删除 ENTRYPOINT

ruby - bundle 执行中间人服务器未按预期工作

ruby - Github Actions 无法在 ubuntu-18.04.5 上安装 Libv8 gem

ruby - 使用 Rails 安装程序安装后测试 sqlite3 的正确安装

ruby-on-rails - rails : validating a field is present only if another is present

docker - 如何备份和恢复apache ignite docker?

ruby-on-rails - `require:` 在 Rails gemfile 中意味着什么?