Q:

Why does "bundle install --path" break when "bundle install" works?

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

I keep getting the above error only when I use bundle install --path.  The moment I switch to regular bundle install everything works perfectly.
After beating my head against the wall for too many hours I think it's time to ask for help.  How do I get bundle install --path working?  I assume it has something to do with bundle environment within a docker container?

This bundle env works:
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"

This bundle env doesn't work:
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:

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

gem "mysql2"
gem "sequel"

group :test do
  gem "rspec"
end

A:

This is caused by the following line of your docker-compose.yml:
volumes:
  - .:/usr/src/app

The gems are installed under /usr/src/app/vendor/bundle, but you are mounting the current directory to /usr/src/app in the docker-compose.yml. So you can not see the gems in the image.
You need to change the bundle path or the mount path.

