2

I have a pretty basic "app" which i'm trying to dockerize using some examples found on the internet but, for some reason, it seems that bundler can't see the gems installed in my env.

Gemfile

source 'https://rubygems.org'
gem 'streamio-ffmpeg'

Dockerfile

FROM dpsxp/ffmpeg-with-ruby:2.2.1
MAINTAINER mike

RUN apt-get update && apt-get install -y \
  build-essential \
  cmake

ENV APP_HOME=/app

RUN mkdir -p $APP_HOME
WORKDIR $APP_HOME

COPY Gemfile* ./
ENV BUNDLE_GEMFILE=$APP_HOME/Gemfile \
  BUNDLE_PATH=/bundle
RUN gem install bundler
RUN bundle install --jobs 20 --retry 5 --path=/bundle

COPY . ./

CMD ["rake"]

docker-compose.yml

version: '2'

services:
  app:
    build:
      context: .
    volumes:
      - '.:/app'
    depends_on:
      - bundle

  bundle:
    image: busybox
    volumes:
      - /bundle

And now, when i'm running $ docker-compose run app gem list, the streamio-ffmpeg gem is not on the list for some reason. Also, when i'm trying to require it inside my ruby app, i'm getting LoadError: cannot load such file

Build logs: https://gist.github.com/mbajur/569b4f221cadb8a85ecc5dae8a595401

mbajur
  • 4,406
  • 5
  • 49
  • 79
  • 1
    Build logs would be relevant here – user2105103 Nov 12 '16 at 19:02
  • Why do you need cmake? Also, that bundle container doesn't seem to be doing anything beneficial either. The `bundle install` command looks like it would fail too. – Matthew Schuchard Nov 12 '16 at 19:53
  • @user2105103 - logs added – mbajur Nov 12 '16 at 20:00
  • @MattSchuchard - i'm using bundle service to persist my gems between main app image builds. Cmake is indeed a bit obsolete, i just copied it from some other container cause it was needed for one of gems used but, anyway, i don't think it's the reason. – mbajur Nov 12 '16 at 20:01
  • CMake is not obsolete. CMake is the standard software for building C++, which is why I asked why it was being included with a ruby app. Also, if you are installing this gem with bundle, then you need to use `bundle` to look for the gem inside your container and not `gem`. – Matthew Schuchard Nov 12 '16 at 20:04
  • try define in Dockerfile sequence commands WORKDIR and COPY below FROM – Darlan Dieterich Nov 13 '20 at 16:52

1 Answers1

3

When you deal with gems by bundler, all related commands should be run with bundle exec, so in your case, it should work with below command:

docker-compose run app bundle exec gem list

Bundler provides a consistent environment for Ruby projects by tracking and installing the exact gems and versions that are needed.

The command you run directly with gem list is to list the system gems, of course they are not in list.

BMW
  • 42,880
  • 12
  • 99
  • 116