Search code examples
rubydockerbundler

How to fix ruby-bundler include of concurrent-ruby on Alpine in Docker?


Not sure if the problem is specific to concurrent-ruby or not, but require doesn't work as expected. I'm a bit at a loss of how to debug this. It works when run as a normal user outside of Docker on Ubuntu. Unfortunately it's not possible to strace a process within Docker to see where it diverges. Any ideas?

Update: it seems the problem is related to the --path ./vendor/bundle option - it works without it, doesn't work with it.

FROM alpine:3.10.2
RUN apk add bash
SHELL ["/bin/bash", "-c"]
RUN apk add npm ruby-bundler
RUN mkdir /app
WORKDIR /app
RUN echo -e "source 'https://rubygems.org'\n\
gem 'concurrent-ruby', require: 'concurrent'\n" >> ./Gemfile
RUN bundle install --path ./vendor/bundle
RUN ruby -e 'require("concurrent")'

Outputs:

Step 9/9 : RUN ruby -e 'require("concurrent")'
 ---> Running in efbb0ed5794f
/usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': cannot load such file -- concurrent (LoadError)
    from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
    from -e:1:in `<main>'
The command '/bin/bash -c ruby -e 'require("concurrent")'' returned a non-zero code: 1

Solution

  • Found the problem, one needs to use bundle exec to launch the ruby application that will do the require operation.