为什么“捆绑安装”工作时“捆绑安装 - 路径”会中断?

时间:2017-01-17 11:13:15

标签: ruby docker bundler

  

`require':LoadError:无法加载这样的文件 - mysql2 / mysql2   (续集:: AdapterNotFound)

我只在使用bundle install --path时才会收到上述错误。我切换到常规bundle install时,一切都很完美。

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

此捆绑环境有效:

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

搬运工-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:

的Gemfile

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

gem "mysql2"
gem "sequel"

group :test do
  gem "rspec"
end

1 个答案:

答案 0 :(得分:1)

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

volumes:
  - .:/usr/src/app

宝石安装在/usr/src/app/vendor/bundle下,但您将当前目录挂载到/usr/src/app中的docker-compose.yml。所以你无法在图像中看到宝石。

您需要更改捆绑路径或装载路径。