【问题标题】:Why does "bundle install --path" break when "bundle install" works?为什么当“bundle install”工作时“bundle install --path”会中断?
【发布时间】:2017-01-17 11:13:14
【问题描述】:

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

只有当我使用bundle install --path 时,我才会不断收到上述错误。当我切换到普通的bundle install 时,一切正常。

在将我的头撞在墙上太多小时后,我认为是时候寻求帮助了。我如何让bundle install --path 工作?我认为它与 docker 容器中的捆绑环境有关?


此捆绑包环境有效:

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"

此捆绑包环境不起作用:

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:

宝石文件

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

gem "mysql2"
gem "sequel"

group :test do
  gem "rspec"
end

【问题讨论】:

    标签: ruby docker bundler


    【解决方案1】:

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

    volumes:
      - .:/usr/src/app
    

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

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

    【讨论】:

    • 我的应用位于/usr/src/app,但希望将gem 安装到/usr/src/app/vendor/bundle。在那种情况下,我要安装什么。在 Dockerfile 中有 COPY . /usr/src/app 不起作用
    • 在我看来,如果你为每个应用程序构建一个镜像,那么没有必要设置一个bundle路径。但是如果你想将 gems 安装到/usr/src/app/vendor/bundle,你可以在安装后捆绑安装并将 gems 保存在主机上。
    猜你喜欢
    • 1970-01-01
    • 2017-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-05
    • 1970-01-01
    • 2017-12-20
    • 1970-01-01
    相关资源
    最近更新 更多