LoginSignup
maasiii
@maasiii

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

LoadError: Could not open library 'vips.so.42' Docker rails

知りたいこと
doker環境でlibvipsをインストールする方法

実現したいこと(仕様や機能など)
libvipsをインストールし、active storageをインストールできるようにしたい。

起きている問題(エラー文など)

rails active_storage:install

するも、libvipsファイルが見つかならいエラーになる。(コンテナの中に入って実施してます。)

rails aborted!
LoadError: Could not open library 'vips.so.42': vips.so.42: cannot open shared object file: No such file or directory.
Could not open library 'libvips.so.42': libvips.so.42: cannot open shared object file: No such file or directory
/usr/local/bundle/gems/ffi-1.15.5/lib/ffi/library.rb:145:in `block in ffi_lib'
/usr/local/bundle/gems/ffi-1.15.5/lib/ffi/library.rb:99:in `map'
/usr/local/bundle/gems/ffi-1.15.5/lib/ffi/library.rb:99:in `ffi_lib'
/usr/local/bundle/gems/ruby-vips-2.1.4/lib/vips.rb:573:in `<module:Vips>'
/usr/local/bundle/gems/ruby-vips-2.1.4/lib/vips.rb:570:in `<main>'
/usr/local/bundle/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/usr/local/bundle/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/usr/local/bundle/gems/ruby-vips-2.1.4/lib/ruby-vips.rb:1:in `<main>'
/usr/local/bundle/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/usr/local/bundle/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/usr/local/bundle/gems/bundler-2.3.23/lib/bundler/runtime.rb:60:in `block (2 levels) in require'
/usr/local/bundle/gems/bundler-2.3.23/lib/bundler/runtime.rb:55:in `each'
/usr/local/bundle/gems/bundler-2.3.23/lib/bundler/runtime.rb:55:in `block in require'
/usr/local/bundle/gems/bundler-2.3.23/lib/bundler/runtime.rb:44:in `each'
/usr/local/bundle/gems/bundler-2.3.23/lib/bundler/runtime.rb:44:in `require'
/usr/local/bundle/gems/bundler-2.3.23/lib/bundler.rb:187:in `require'
/myapp/config/application.rb:7:in `<main>'
/myapp/rakefile:4:in `require_relative'
/myapp/rakefile:4:in `<main>'
/usr/local/bundle/gems/railties-7.0.4.3/lib/rails/commands/rake/rake_command.rb:20:in `block in perform'
/usr/local/bundle/gems/railties-7.0.4.3/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/usr/local/bundle/gems/railties-7.0.4.3/lib/rails/command.rb:51:in `invoke'
/usr/local/bundle/gems/railties-7.0.4.3/lib/rails/commands.rb:18:in `<main>'
/usr/local/bundle/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/usr/local/bundle/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
bin/rails:4:in `<main>'
(See full trace by running task with --trace)

自ら考えてみた仮説
単純にコンテナにパッケージがインストールされておらず、ファイルが見つからないのかもしれない。(Dockerfileの記述ミス、、?)

やってみたこと
まず初めにGemfileに以下を記述し、インストールするも、動かず。

gem 'ruby-vips', '~> 2.1', '>= 2.1.4'

次に、こちらを参考に、vipsをインストールしても変化なし。

$ brew install vips

Docker環境はやはり少し違うのかもしれないと思い、こちらを参考に、Dockerfileにlibvips42を記述し、再buildするも変化なしでした。

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

現時点での自分なりの結論
おそらくDocker関連の設定などがおかしいのかもしれないが、Docker libvipsに関する記事もあまり見つけられず解決の余地が現状見えない。

知見をお持ちの方いらっしゃいましたら、ご教授いただけますと幸いです🙇

参考(記事URLやソースコードなど)

Dockerfile

FROM ruby:3.1.2

# 必要なパッケージをインストール
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs vim libvips42

# Yarnのインストール
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
  && echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
  && apt-get update && apt-get install -y yarn

# アプリケーションディレクトリの作成
RUN mkdir /myapp
WORKDIR /myapp

# Gemfileをコピー
ADD Gemfile /myapp/Gemfile
ADD Gemfile.lock /myapp/Gemfile.lock

# BundlerでGemをインストール
RUN bundle install

# アプリケーションのソースコードをコピー
ADD . /myapp

Gemfile

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

ruby "3.1.2"
gem 'bootstrap', '~> 5.1'
gem 'sass-rails', '>= 6'
gem 'jquery-rails'
gem 'ruby-vips', '~> 2.1', '>= 2.1.4'
gem "image_processing", ">= 1.2"

# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.0.4", ">= 7.0.4.3"

# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
gem "sprockets-rails"

# Use postgresql as the database for Active Record
gem "pg", "~> 1.1"

# Use the Puma web server [https://github.com/puma/puma]
gem "puma", "~> 5.0"

# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
gem "importmap-rails"

# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
gem "turbo-rails"

# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
gem "stimulus-rails"

# Build JSON APIs with ease [https://github.com/rails/jbuilder]
gem "jbuilder"

# Use Redis adapter to run Action Cable in production
# gem "redis", "~> 4.0"

# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
# gem "kredis"

# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
gem "bcrypt", "~> 3.1.7"

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]

# Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", require: false

# Use Sass to process CSS
# gem "sassc-rails"

# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"

group :development, :test do
  # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
  gem "debug", platforms: %i[ mri mingw x64_mingw ]
end

group :development do
  # Use console on exceptions pages [https://github.com/rails/web-console]
  gem "web-console"

  # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
  # gem "rack-mini-profiler"

  # Speed up commands on slow machines / big apps [https://github.com/rails/spring]
  # gem "spring"
end

group :test do
  # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
  gem "capybara"
  gem "selenium-webdriver"
  gem "webdrivers"
end

ruby-vips
libvips

0

1Answer

Your answer might help someone💌