当Docker更改了BUNDLE_PATH时,捆绑程序找不到安装的gem [英] Installed gems not found by bundler when BUNDLE_PATH changed with Docker

查看:166
本文介绍了当Docker更改了BUNDLE_PATH时,捆绑程序找不到安装的gem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用docker开发Rails应用程序。 docker文件如下所示:

I'm using docker to develop a rails application. The docker file looks like this:

FROM ruby:1.9.3

RUN apt-get update -qq && apt-get install -y build-essential libpq-dev vim

ENV APP_HOME /next-reg
RUN mkdir $APP_HOME
WORKDIR $APP_HOME

ENV BUNDLE_PATH /box

ADD . $APP_HOME

RUN gem install gem1.gem  gem2.gem

COPY Gemfile Gemfile
COPY Gemfile.lock Gemfile.lock

RUN  bundle install

如您所见,我更改了 BUNDLE_PATH ,这是因为 an文章,展示了我们如何持久保存gem下载。这样,当docker缓存变暖时就会超时,它会重新捆绑并永久使用。

As you can see I change the BUNDLE_PATH, this is because of an article showing how we can persist gem downloads. So that overtime when the docker cache gets warm, it re-bundles and takes FOREVER.

当我 docker build 时它成功安装了gem,然后在捆绑包中找不到它们。

When I docker build it successfully installs the gems, then it fails to find them on bundle. Could someone give me a hand with persisting gems, installing my own gems, and getting it to work?

在我更改 BUNDLE_PATH 之前,有人可以帮我解决持久性宝石,安装自己的宝石并使其工作吗? c $ c>构建工作正常,它只是频繁地捆绑在一起而没有更改gem文件(因为我想docker映像缓存很热)。

Before I changed the BUNDLE_PATH the build worked, it just re bundled frequently without changes to the gem file (because, I guess the docker image cache got warm).

我的docker-撰写是这样的:

My docker-compose is like this:

db:
  image: postgres
  volumes:
    - ~/.docker-voumes/postgres/data:/var/lib/postgresql/data
# This is to hold and persist ruby gems, referenced in web and in web's dockerfile.
gem_files:
  image: busybox
  volumes:
    - /box

web:
  build: .
  command: bundle exec rails s -p 3000 -b '0.0.0.0'
  volumes:
    - .:/next-reg
  volumes_from: 
    - gem_files
  ports:
    - "3000:3000"
    - "8000:8000"
  links:
    - db
  env_file:
    - .myenv.env


推荐答案

如果有人需要答案:

我认为您的代码中缺少GEM_HOME / GEM_PATH。

I think that there is a lack of GEM_HOME/GEM_PATH in your code.

GEM_HOME / GEM_PATH将被使用通过gem install xxx可以在特定文件夹中安装gem。
BUNDLE_PATH将由捆绑包安装用于将gems安装到特定文件夹中,而不由gem install xx

GEM_HOME/GEM_PATH will be used by gem install xxx to install gems in a specific folder. BUNDLE_PATH will be used by bundle install to install gems in a specific folder but not by gem install xx

要拥有一个工作系统,您应该这样做:

To have a working system you should do :

FROM ruby:1.9.3

RUN apt-get update -qq && apt-get install -y build-essential libpq-dev vim
ENV APP_HOME /next-reg
RUN mkdir $APP_HOME
WORKDIR $APP_HOME

ENV BUNDLE_PATH /box
ENV GEM_PATH /box
ENV GEM_HOME /box

ADD . $APP_HOME

RUN gem install bundler
RUN gem install tzinfo -v 1.2.2

COPY Gemfile Gemfile

RUN  bundle install

使用此Gemfile:

With this Gemfile :

source 'https://rubygems.org'

gem 'tzinfo', '1.2.2'

将会产生:


Step 11/13 : RUN gem install tzinfo -v 1.2.2
 ---> Running in 8a87fa54fa19
Successfully installed thread_safe-0.3.6
Successfully installed tzinfo-1.2.2
2 gems installed
 ---> 3c91d59bde8a
Removing intermediate container 8a87fa54fa19

Step 13/13 : RUN bundle install
 ---> Running in 20f1e4ec93b1
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and
installing your bundle as root will break this application for all non-root
users on this machine.
Fetching gem metadata from https://rubygems.org/...
Fetching version metadata from https://rubygems.org/.
Resolving dependencies...
Rubygems 1.8.23.2 is not threadsafe, so your gems will be installed one at a time. Upgrade to Rubygems 2.1.0 or higher to enable parallel gem installation.
Installing rake 12.0.0
Using thread_safe 0.3.6
Using bundler 1.14.6
Using tzinfo 1.2.2
Bundle complete! 2 Gemfile dependencies, 4 gems now installed.
Bundled gems are installed into /box.

如您在结果输出中看到的,捆绑安装来自宝石安装

As you can see in the result output, the bundle install re-use the preloaded gems from gem install

这篇关于当Docker更改了BUNDLE_PATH时,捆绑程序找不到安装的gem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆