Installed gems not found by the vendor when BUNDLE_PATH changed using Docker

I am using docker to develop an application for rails. The docker file is as follows:

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 

As you can see, I am changing bundle_path , this is due to an article showing how we can save the gem load. So overtime, when the docker cache heats up, it merges again and takes FOREVER.

When I docker build it successfully installs gems, then it cannot find them in the package. Can someone give me a hand with persisting gems, set my own gems and make it work?

Before I changed bundle_path , the assembly worked, it was simply re-included often without changes to the gem file (because, I think, the docker image cache was hot).

My docker layout is as follows:

 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 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 
+5
source share
1 answer

In case someone needs an answer:

I think your code is missing GEM_HOME / GEM_PATH.

GEM_HOME / GEM_PATH will be used by gem install xxx to install gems in a specific folder. BUNDLE_PATH will be used by installing the package to install gems in a specific folder, but not with gem install xx

To have a working system, you should:

 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 

With this gemfile:

 source 'https://rubygems.org' gem 'tzinfo', '1.2.2' 

which will produce:

  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 from the output, bundle install reused preloaded gems from gem install

+2
source

Source: https://habr.com/ru/post/1241533/


All Articles