【问题标题】:Why is "bundle install" returning an error when building my docker repository?为什么在构建我的 docker 存储库时“捆绑安装”返回错误?
【发布时间】:2020-02-15 22:37:06
【问题描述】:

我正在学习如何使用 docker 构建 Rails 应用程序,每次尝试运行 $ docker-compose build web 时都会收到以下错误:

You must use Bundler 2 or greater with this lockfile.
ERROR: Service 'web' failed to build: The command '/bin/sh -c bundle install' returned a non-zero code: 20

这是我的 Dockerfile:

FROM ruby:2.5.1

ENV APP_HOME /usr/src/app
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev

# Node.js
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - \
&& apt-get install -y nodejs

RUN apt-get update && apt-get install -y curl apt-transport-https wget && \
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
apt-get update && apt-get install -y yarn

# SOURCE CODE

WORKDIR $APP_HOME

COPY . $APP_HOME/
RUN gem install bundler --version 2.0.2 --no-rdoc --no-ri
ADD Gemfile $APP_HOME/
ADD Gemfile.lock $APP_HOME/
RUN bundle install
RUN echo '--color' >> ~/.rspec

这是我的 docker-compose.yml 文件

version: '3'
services:
  db:
    image: postgres
  webpacker:
    build: .
    command: bundle exec bin/webpack-dev-server
    volumes:
      - .:/fancyapp
    ports:
      - "8080:8080"
  web:
    build: .
    command: bundle exec rails s -p 3000 -b '0.0.0.0'
    volumes:
      - .:/fancyapp
    ports:
      - "3000:3000"
    depends_on:
      - db
      - webpacker

我完全是 docker 的菜鸟,老实说,我看不出这里有什么问题。 我的实现基于this tutorial

【问题讨论】:

  • 您的绑定挂载将 ./vendor 隐藏在容器内,其中包含本地源代码树中的任何内容。这可能相关也可能不相关。如果从docker-compose.yml文件中删除volumes:是否有效(确保COPYDockerfile中的应用程序代码)?

标签: ruby-on-rails docker ruby-on-rails-5 bundle bundler


【解决方案1】:

似乎在您的Gemfile.lock 中说您使用版本高于 2 的 bundler。在这种情况下,您可以使用 2 种方式:

  1. 降低本地版本

  2. 添加到您的 docker 文件字符串 gem install bundler(无版本)。它将最后安装bundler

【讨论】:

    【解决方案2】:

    运行命令gem list bundler,我猜你的bundler版本低于2。

    如果是这样,运行gem install bundler -v 2.0.2 安装最新的。

    您可以运行gem install --default bundler -v 2.0.2 使其成为要使用的默认版本。

    【讨论】:

      猜你喜欢
      • 2016-04-14
      • 1970-01-01
      • 2019-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多