Docker依赖问题:Rake中止! LoadError:无法加载这样的文件 – sqlite3 / sqlite3_native

我有问题试图解决这个依赖性问题。 我有我的gemfile sqlite3,我可以看到它安装,甚至当我运行gem list (在我的docker集装箱内)。 但是,当我用docker build生成我的依赖时,然后在一个容器中运行我的项目,当运行rake test时出现以下错误

  root@401a61839c07:/app# rake test rake aborted! LoadError: cannot load such file -- sqlite3/sqlite3_native 

这是构build,你可以清楚地看到,安装了SQLite。

 docker build -f DependenciesDockerfile -t visual-base . . . . Step 12 : RUN bundle install --without development ---> Running in 623d8b439808 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/... Fetching dependency metadata from https://rubygems.org/.. Installing rake 10.5.0 Installing i18n 0.7.0 Installing json 1.8.3 Installing minitest 5.8.4 Installing thread_safe 0.3.5 Installing tzinfo 1.2.2 Installing activesupport 4.1.6 Installing builder 3.2.2 Installing erubis 2.7.0 Installing actionview 4.1.6 Installing rack 1.5.5 Installing rack-test 0.6.3 Installing actionpack 4.1.6 Installing mime-types 2.99.1 Installing mail 2.6.3 Installing actionmailer 4.1.6 Installing activemodel 4.1.6 Installing arel 5.0.1.20140414130214 Installing activerecord 4.1.6 Installing execjs 2.6.0 Installing autoprefixer-rails 6.3.3.1 Installing bcrypt 3.1.11 Installing sass 3.2.19 Installing bootstrap-sass 3.3.5 Installing climate_control 0.0.3 Installing cocaine 0.5.8 Installing coffee-script-source 1.10.0 Installing coffee-script 2.4.1 Using thor 0.19.1 Installing railties 4.1.6 Installing coffee-rails 4.0.1 Installing jquery-rails 3.1.4 Using bundler 1.8.0 Installing hike 1.2.3 Installing multi_json 1.11.2 Installing tilt 1.4.1 Installing sprockets 2.12.4 Installing sprockets-rails 2.3.3 Installing rails 4.1.6 Installing commontator 4.10.5 Installing orm_adapter 0.5.0 Installing responders 1.1.2 Installing warden 1.2.6 Installing devise 3.5.6 Installing devise-bootstrap-views 0.0.8 Installing gretel 3.0.8 Installing jbuilder 2.4.1 Installing kgio 2.10.0 Installing mimemagic 0.3.0 Installing net-ldap 0.14.0 Installing paperclip 4.3.5 Installing pg 0.18.4 Installing polyamorous 1.1.0 Installing raindrops 0.16.0 Installing rdoc 4.2.2 Installing rmagick 2.13.3 Installing sass-rails 4.0.5 Installing sdoc 0.4.1 Installing sqlite3 1.3.11 Installing squeel 1.2.3 Installing turbolinks 2.5.3 Installing uglifier 2.7.2 Installing unicorn 5.0.1 Bundle complete! 28 Gemfile dependencies, 63 gems now installed. Gems in the group development were not installed. Use `bundle show [gemname]` to see where a bundled gem is installed. Post-install message from rdoc: Depending on your version of ruby, you may need to install ruby rdoc/ri data: <= 1.8.6 : unsupported = 1.8.7 : gem install rdoc-data; rdoc-data --install = 1.9.1 : gem install rdoc-data; rdoc-data --install >= 1.9.2 : nothing to do! Yay! Post-install message from rmagick: Please report any bugs. See https://github.com/gemhome/rmagick/compare/RMagick_2-13-2...master and https://github.com/rmagick/rmagick/issues/18 ---> 901bbde8aa4f Removing intermediate container 623d8b439808 Successfully built 901bbde8aa4f 2.2.3 in visual-automation/ on master › docker build -t visual . Sending build context to Docker daemon 112.3 MB Step 1 : FROM visual-base ---> 901bbde8aa4f Step 2 : MAINTAINER ---> Running in bd02c1f718e7 ---> 02f76881207c Removing intermediate container bd02c1f718e7 Step 3 : ADD . /app ---> 4f80ec7fccce Removing intermediate container 6d73bdc55fde Step 4 : RUN sed -i.bak 's/user www-data;/user root;/g' /etc/nginx/nginx.conf ---> Running in df22155ce2b7 ---> aa9442d89c9e Removing intermediate container df22155ce2b7 Step 5 : EXPOSE 80 ---> Running in f839dd6707ce ---> d197974fa925 Removing intermediate container f839dd6707ce Successfully built d197974fa925 2.2.3 in repo/ on master › docker run -it visual /bin/bash root@401a61839c07:/app# rake test rake aborted! LoadError: cannot load such file -- sqlite3/sqlite3_native /app/vendor/cache/ruby/2.2.0/gems/sqlite3-1.3.11/lib/sqlite3.rb:6:in `require' /app/vendor/cache/ruby/2.2.0/gems/sqlite3-1.3.11/lib/sqlite3.rb:6:in `rescue in <top (required)>' /app/vendor/cache/ruby/2.2.0/gems/sqlite3-1.3.11/lib/sqlite3.rb:2:in `<top (required)>' /app/config/application.rb:7:in `<top (required)>' /app/Rakefile:4:in `<top (required)>' LoadError: cannot load such file -- sqlite3/2.2/sqlite3_native /app/vendor/cache/ruby/2.2.0/gems/sqlite3-1.3.11/lib/sqlite3.rb:4:in `require' /app/vendor/cache/ruby/2.2.0/gems/sqlite3-1.3.11/lib/sqlite3.rb:4:in `<top (required)>' /app/config/application.rb:7:in `<top (required)>' /app/Rakefile:4:in `<top (required)>' (See full trace by running task with --trace) root@401a61839c07:/app# 

这是在容器内运行时的gem list的输出

 root@69296d7eec2a:/app# gem list *** LOCAL GEMS *** actionmailer (4.1.6) actionpack (4.1.6) actionview (4.1.6) activemodel (4.1.6) activerecord (4.1.6) activesupport (4.1.6) arel (5.0.1.20140414130214) autoprefixer-rails (5.2.1.1) bcrypt (3.1.10) bigdecimal (1.2.6) bootstrap-sass (3.3.5) builder (3.2.2) bundler (1.8.0) climate_control (0.0.3) cocaine (0.5.8) coffee-rails (4.0.1) coffee-script (2.4.1) coffee-script-source (1.9.1.1) commontator (4.10.5) devise (3.5.1) devise-bootstrap-views (0.0.5) dotenv (1.0.2) erubis (2.7.0) execjs (2.5.2) foreman (0.77.0) gretel (3.0.8) hike (1.2.3) i18n (0.7.0) io-console (0.4.3) jbuilder (2.3.1) jquery-rails (3.1.3) json (1.8.3, 1.8.1) kgio (2.9.3) mail (2.6.3) mime-types (2.6.1) mimemagic (0.3.0) minitest (5.8.4, 5.4.3) multi_json (1.11.2) net-ldap (0.11) orm_adapter (0.5.0) paperclip (4.3.5) pg (0.18.3) polyamorous (1.1.0) power_assert (0.2.2) psych (2.0.8) rack (1.5.5) rack-test (0.6.3) rails (4.1.6) railties (4.1.6) raindrops (0.15.0) rake (10.4.2) rdoc (4.2.0) responders (1.1.2) rmagick (2.13.3) sass (3.2.19) sass-rails (4.0.5) sdoc (0.4.1) sprockets (2.12.4) sprockets-rails (2.3.2) sqlite3 (1.3.11) squeel (1.2.3) test-unit (3.0.8) thor (0.19.1) thread_safe (0.3.5) tilt (1.4.1) turbolinks (2.5.3) tzinfo (1.2.2) uglifier (2.7.1) unicorn (4.9.0) warden (1.2.3) 

我已经通过编辑gemspecs看到了临时解决scheme,但是一旦你修复了一个,就会popup另一个类似的错误。 我必须错过一些东西,但看起来一切都是为了。

任何帮助将非常感激

从ruby的文档https://github.com/sparklemotion/sqlite3-ruby它&#x8BF4;

该模块允许Ruby程序与SQLite3数据库引擎(www.sqlite.org)进行交互。 您必须安装SQLite引擎才能构build此模块。

我认为这里的问题是你的docker容器没有安装sqlite3引擎,所以当gem试图调用本地代码时,它不能。

validation你的Dockerfile中有一行像RUN apt-get sqlite3