4

I'm trying to containerize my Rails app and boot it via docker-compose. The app builds fine via docker-compose build but when trying to boot, it fails:

$ docker-compose up   
Starting postgres ... done
Recreating puma   ... done
Attaching to postgres, puma
postgres    | 
postgres    | PostgreSQL Database directory appears to contain a database; Skipping initialization
postgres    | 
postgres    | 2022-05-04 21:45:30.012 UTC [1] LOG:  starting PostgreSQL 14.1 (Debian 14.1-1.pgdg110+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
postgres    | 2022-05-04 21:45:30.012 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
postgres    | 2022-05-04 21:45:30.012 UTC [1] LOG:  listening on IPv6 address "::", port 5432
postgres    | 2022-05-04 21:45:30.016 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres    | 2022-05-04 21:45:30.075 UTC [28] LOG:  database system was shut down at 2022-05-04 21:31:01 UTC
postgres    | 2022-05-04 21:45:30.119 UTC [1] LOG:  database system is ready to accept connections
puma        | /usr/local/bundle/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:15:in `require': cannot load such file -- nokogiri (LoadError)

I'm specifically struggling with this last line:

1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:15:in `require': cannot load such file -- nokogiri (LoadError)

My Dockerfile is as follows:

# syntax=docker/dockerfile:1
FROM ruby:3.0.4
RUN apt-get update && apt-get install -y nodejs postgresql-client zlib1g-dev liblzma-dev patch
RUN gem install nokogiri --platform=ruby
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle install

# Add a script to be executed every time the container starts.
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000

# Configure the main process to run when running the image
CMD ["rails", "server", "-b", "0.0.0.0"]

I've tried following the recommendations here, noting that Docker is building its images with Debian. But, this doesn't seem to work.

I also came across this post, but in this case I'm not building with Alpine Linux, I'm using the default ruby image image which appears to run on Debian. That, I'm also attempting to boot on my M1 macOS (11.3.1) machine.

Any recommendations or tips here? I'm relatively new to building Rails apps via Docker and any tips would be much appreciated .


Lastly, here are my Gemfile and Gemfile.lock files respectively:

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

ruby '3.0.4'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 6.1.4', '>= 6.1.4.4'
# 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 'sass-rails', '>= 6'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'

gem "sidekiq"

gem "httparty"

gem "bootstrap"

gem "sidekiq-scheduler"

# 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]
  gem 'dotenv-rails'
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'
  # 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
  remote: https://rubygems.org/
  specs:
    actioncable (6.1.4.6)
      actionpack (= 6.1.4.6)
      activesupport (= 6.1.4.6)
      nio4r (~> 2.0)
      websocket-driver (>= 0.6.1)
    actionmailbox (6.1.4.6)
      actionpack (= 6.1.4.6)
      activejob (= 6.1.4.6)
      activerecord (= 6.1.4.6)
      activestorage (= 6.1.4.6)
      activesupport (= 6.1.4.6)
      mail (>= 2.7.1)
    actionmailer (6.1.4.6)
      actionpack (= 6.1.4.6)
      actionview (= 6.1.4.6)
      activejob (= 6.1.4.6)
      activesupport (= 6.1.4.6)
      mail (~> 2.5, >= 2.5.4)
      rails-dom-testing (~> 2.0)
    actionpack (6.1.4.6)
      actionview (= 6.1.4.6)
      activesupport (= 6.1.4.6)
      rack (~> 2.0, >= 2.0.9)
      rack-test (>= 0.6.3)
      rails-dom-testing (~> 2.0)
      rails-html-sanitizer (~> 1.0, >= 1.2.0)
    actiontext (6.1.4.6)
      actionpack (= 6.1.4.6)
      activerecord (= 6.1.4.6)
      activestorage (= 6.1.4.6)
      activesupport (= 6.1.4.6)
      nokogiri (>= 1.8.5)
    actionview (6.1.4.6)
      activesupport (= 6.1.4.6)
      builder (~> 3.1)
      erubi (~> 1.4)
      rails-dom-testing (~> 2.0)
      rails-html-sanitizer (~> 1.1, >= 1.2.0)
    activejob (6.1.4.6)
      activesupport (= 6.1.4.6)
      globalid (>= 0.3.6)
    activemodel (6.1.4.6)
      activesupport (= 6.1.4.6)
    activerecord (6.1.4.6)
      activemodel (= 6.1.4.6)
      activesupport (= 6.1.4.6)
    activestorage (6.1.4.6)
      actionpack (= 6.1.4.6)
      activejob (= 6.1.4.6)
      activerecord (= 6.1.4.6)
      activesupport (= 6.1.4.6)
      marcel (~> 1.0.0)
      mini_mime (>= 1.1.0)
    activesupport (6.1.4.6)
      concurrent-ruby (~> 1.0, >= 1.0.2)
      i18n (>= 1.6, < 2)
      minitest (>= 5.1)
      tzinfo (~> 2.0)
      zeitwerk (~> 2.3)
    addressable (2.8.0)
      public_suffix (>= 2.0.2, < 5.0)
    autoprefixer-rails (10.4.0.0)
      execjs (~> 2)
    bindex (0.8.1)
    bootsnap (1.10.3)
      msgpack (~> 1.2)
    bootstrap (5.1.3)
      autoprefixer-rails (>= 9.1.0)
      popper_js (>= 2.9.3, < 3)
      sassc-rails (>= 2.0.0)
    builder (3.2.4)
    byebug (11.1.3)
    capybara (3.36.0)
      addressable
      matrix
      mini_mime (>= 0.1.3)
      nokogiri (~> 1.8)
      rack (>= 1.6.0)
      rack-test (>= 0.6.3)
      regexp_parser (>= 1.5, < 3.0)
      xpath (~> 3.2)
    childprocess (4.1.0)
    concurrent-ruby (1.1.9)
    connection_pool (2.2.5)
    crass (1.0.6)
    dotenv (2.7.6)
    dotenv-rails (2.7.6)
      dotenv (= 2.7.6)
      railties (>= 3.2)
    e2mmap (0.1.0)
    erubi (1.10.0)
    et-orbi (1.2.7)
      tzinfo
    execjs (2.8.1)
    ffi (1.15.5)
    fugit (1.5.3)
      et-orbi (~> 1, >= 1.2.7)
      raabro (~> 1.4)
    globalid (1.0.0)
      activesupport (>= 5.0)
    httparty (0.20.0)
      mime-types (~> 3.0)
      multi_xml (>= 0.5.2)
    i18n (1.10.0)
      concurrent-ruby (~> 1.0)
    jbuilder (2.11.5)
      actionview (>= 5.0.0)
      activesupport (>= 5.0.0)
    listen (3.7.1)
      rb-fsevent (~> 0.10, >= 0.10.3)
      rb-inotify (~> 0.9, >= 0.9.10)
    loofah (2.14.0)
      crass (~> 1.0.2)
      nokogiri (>= 1.5.9)
    mail (2.7.1)
      mini_mime (>= 0.1.1)
    marcel (1.0.2)
    matrix (0.4.2)
    method_source (1.0.0)
    mime-types (3.4.1)
      mime-types-data (~> 3.2015)
    mime-types-data (3.2021.1115)
    mini_mime (1.1.2)
    minitest (5.15.0)
    msgpack (1.4.5)
    multi_xml (0.6.0)
    nio4r (2.5.8)
    nokogiri (1.13.3-arm64-darwin)
      racc (~> 1.4)
    pg (1.3.3)
    popper_js (2.9.3)
    public_suffix (4.0.6)
    puma (5.6.2)
      nio4r (~> 2.0)
    raabro (1.4.0)
    racc (1.6.0)
    rack (2.2.3)
    rack-mini-profiler (2.3.4)
      rack (>= 1.2.0)
    rack-test (1.1.0)
      rack (>= 1.0, < 3)
    rails (6.1.4.6)
      actioncable (= 6.1.4.6)
      actionmailbox (= 6.1.4.6)
      actionmailer (= 6.1.4.6)
      actionpack (= 6.1.4.6)
      actiontext (= 6.1.4.6)
      actionview (= 6.1.4.6)
      activejob (= 6.1.4.6)
      activemodel (= 6.1.4.6)
      activerecord (= 6.1.4.6)
      activestorage (= 6.1.4.6)
      activesupport (= 6.1.4.6)
      bundler (>= 1.15.0)
      railties (= 6.1.4.6)
      sprockets-rails (>= 2.0.0)
    rails-dom-testing (2.0.3)
      activesupport (>= 4.2.0)
      nokogiri (>= 1.6)
    rails-html-sanitizer (1.4.2)
      loofah (~> 2.3)
    railties (6.1.4.6)
      actionpack (= 6.1.4.6)
      activesupport (= 6.1.4.6)
      method_source
      rake (>= 0.13)
      thor (~> 1.0)
    rake (13.0.6)
    rb-fsevent (0.11.1)
    rb-inotify (0.10.1)
      ffi (~> 1.0)
    redis (4.6.0)
    regexp_parser (2.2.1)
    rexml (3.2.5)
    rubyzip (2.3.2)
    rufus-scheduler (3.8.1)
      fugit (~> 1.1, >= 1.1.6)
    sass-rails (6.0.0)
      sassc-rails (~> 2.1, >= 2.1.1)
    sassc (2.4.0)
      ffi (~> 1.9)
    sassc-rails (2.1.2)
      railties (>= 4.0.0)
      sassc (>= 2.0)
      sprockets (> 3.0)
      sprockets-rails
      tilt
    selenium-webdriver (4.1.0)
      childprocess (>= 0.5, < 5.0)
      rexml (~> 3.2, >= 3.2.5)
      rubyzip (>= 1.2.2)
    sidekiq (6.4.1)
      connection_pool (>= 2.2.2)
      rack (~> 2.0)
      redis (>= 4.2.0)
    sidekiq-scheduler (3.1.1)
      e2mmap
      redis (>= 3, < 5)
      rufus-scheduler (~> 3.2)
      sidekiq (>= 3)
      thwait
      tilt (>= 1.4.0)
    spring (3.1.1)
    sprockets (4.0.3)
      concurrent-ruby (~> 1.0)
      rack (> 1, < 3)
    sprockets-rails (3.4.2)
      actionpack (>= 5.2)
      activesupport (>= 5.2)
      sprockets (>= 3.0.0)
    thor (1.2.1)
    thwait (0.2.0)
      e2mmap
    tilt (2.0.10)
    tzinfo (2.0.4)
      concurrent-ruby (~> 1.0)
    web-console (4.2.0)
      actionview (>= 6.0.0)
      activemodel (>= 6.0.0)
      bindex (>= 0.4.0)
      railties (>= 6.0.0)
    webdrivers (5.0.0)
      nokogiri (~> 1.6)
      rubyzip (>= 1.3.0)
      selenium-webdriver (~> 4.0)
    websocket-driver (0.7.5)
      websocket-extensions (>= 0.1.0)
    websocket-extensions (0.1.5)
    xpath (3.2.0)
      nokogiri (~> 1.8)
    zeitwerk (2.5.4)

PLATFORMS
  aarch64-linux
  arm64-darwin-20

DEPENDENCIES
  bootsnap (>= 1.4.4)
  bootstrap
  byebug
  capybara (>= 3.26)
  dotenv-rails
  httparty
  jbuilder (~> 2.7)
  listen (~> 3.3)
  pg (~> 1.1)
  puma (~> 5.0)
  rack-mini-profiler (~> 2.0)
  rails (~> 6.1.4, >= 6.1.4.4)
  sass-rails (>= 6)
  selenium-webdriver
  sidekiq
  sidekiq-scheduler
  spring
  tzinfo-data
  web-console (>= 4.1.0)
  webdrivers

RUBY VERSION
   ruby 3.0.4p208

BUNDLED WITH
   2.2.33

eighdah14
  • 155
  • 6

1 Answers1

8

For anyone that runs into this same issue, I had to perform the below locally and rebuild the container:

bundle lock --add-platform x86_64-linux
bundle install    # resolve dependencies for platform-specific gems

As stated here: https://nokogiri.org/tutorials/installing_nokogiri.html#supported-platforms

tl;dr: RTFM.

eighdah14
  • 155
  • 6
  • 2
    Using an alpine image I had to install additional libraries via `apk add gcompat` as described in https://stackoverflow.com/a/68284294 – bennos Sep 08 '22 at 08:25