繁体   English   中英

Docker Ruby on Rails 容器无法加载此类文件 -- /..bundler-2.2.30/exe/bundle(加载错误)

[英]Docker Ruby on Rails container cannot load such file -- /..bundler-2.2.30/exe/bundle (Load Error)

我正在尝试将我的 RoR 应用程序容器化,并按照本指南成功运行docker-compose build而没有出现问题。 我需要为应用程序本身和 pgsql 数据库创建一个容器。 一旦docker-compose up部分到达,数据库运行完美,但应用程序抛出这个问题:

/usr/local/bundle/bin/bundle:23:in load': cannot load such file --/usr/local/bundle/gems/bundler-2.2.30/exe/bundle (LoadError) app_1| from /usr/local/bundle/bin/bundle:23:in load': cannot load such file --/usr/local/bundle/gems/bundler-2.2.30/exe/bundle (LoadError) app_1| from /usr/local/bundle/bin/bundle:23:in '

我尝试更改 ruby 版本,重新安装所有内容,使用不同的 bundler -v 运行它,但总是遇到同样的问题......遵循我的环境。

我的 Ruby 版本是: 2.6.8p205

我的捆绑器版本是: 2.2.3

这是我的Gemfile

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.6.8'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 6.1.5'
# Use postgresql as the database for Active Record
gem 'pg', '~> 1.1'
# Use Puma as the app server
gem 'puma', '~> 5.0'
# Use SCSS for stylesheets
gem 'sassc', '~> 2.1'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 5.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Active Storage variant
# gem 'image_processing', '~> 1.2'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.4', require: false

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 4.1.0'
# Display performance information such as SQL time and flame graphs for each request in your browser.
# Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md
gem 'rack-mini-profiler', '~> 2.0'
gem 'listen', '~> 3.3'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end

group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 3.26'
gem 'selenium-webdriver', '>= 4.0.0.rc1'
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'devise'
gem 'bootstrap', '~> 5.1.3'
gem 'haml-rails'
gem 'devise-encryptable'
gem 'uuidtools'
gem 'administrate'
gem 'paypal-checkout-sdk'
gem 'pay', '~> 3.0'
gem 'stripe', '>= 5.0', '< 6.0'
gem 'braintree', '>= 4.6', '< 5.0'
gem 'paddle_pay', '~> 0.2'
gem 'receipts', '~> 2.0'
gem 'letter_opener', group: :development
gem 'dotenv'
gem "nokogiri", ">= 1.6.7.rc"

这是我的Dockerfile

FROM ruby:2.6.8-alpine
ENV BUNDLER_VERSION=2.2.3
RUN apk add --update --no-cache \
  binutils-gold \
  build-base \
  curl \
  file \
  g++ \
  gcc \
  git \
  less \
  libstdc++ \
  libffi-dev \
  libc-dev \ 
  linux-headers \
  libxml2-dev \
  libxslt-dev \
  libgcrypt-dev \
  make \
  netcat-openbsd \
  nodejs \
  openssl \
  pkgconfig \
  postgresql-dev \
  tzdata \
  yarn 

RUN gem install bundler -v 2.2.30
RUN gem uninstall nokogiri
WORKDIR /app
RUN gem install nokogiri
COPY Gemfile Gemfile.lock ./
RUN bundle config build.nokogiri --use-system-libraries
RUN bundle check || bundle install
COPY package.json yarn.lock ./
RUN yarn install --check-files
COPY . ./ 

ENTRYPOINT ["./entrypoints/docker-entrypoint.sh"]

这是我的docker-entrypoint.sh

#!/bin/sh
set -e

if [ -f tmp/pids/server.pid ]; then
  rm tmp/pids/server.pid
fi
bundle install
bundle exec rails s -b 0.0.0.0

这是我的docker-compose.yml

version: '3.4'

services:
  app: 
    build:
      context: .
      dockerfile: Dockerfile
    depends_on:
      - database
    ports: 
      - "3000:3000"
    volumes:
      - .:/app
      - gem_cache:/usr/local/bundle/gems
      - node_modules:/app/node_modules
    env_file: .env
    environment:
      RAILS_ENV: development

  database:
    image: postgres:12.1
    volumes:
      - db_data:/var/lib/postgresql/data
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql

volumes:
  gem_cache:
  db_data:
  node_modules:

感谢所有可以帮助我的人...

这是我的 2 个 rails 工作配置,尝试将其用于 gem 安装部分:

RUN gem install bundler:2.2.30 && bundle config set deployment without 'development test' with 'runtime' && bundle install

或者

RUN gem install bundler --no-document
RUN bundle install --no-binstubs --jobs $(nproc) --retry 3 --without development test

没有ENV BUNDLER_VERSION=2.2.3 env

编辑:我忘了说,alpine 给了我一个非 api-only 应用程序的问题,所以我使用了标准的 docker 图像。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM