我有这个Dockerfile
FROM ruby:2.1.5
RUN apt-get update -qq && apt-get install -y build-essential
# for postgres
RUN apt-get install -y libpq-dev
# for nokogiri
RUN apt-get install -y libxml2-dev libxslt1-dev
# for capybara-webkit
RUN apt-get install -y libqt4-webkit libqt4-dev xvfb
# for a JS runtime
RUN apt-get install -y nodejs
# for rmagick
RUN apt-get install -y imagemagick libmagickwand-dev
ENV APP_HOME /lescollectionneurs
RUN mkdir $APP_HOME
WORKDIR $APP_HOME
ADD Gemfile* $APP_HOME/
RUN bundle install
ADD . $APP_HOME
这个Gemfile:
source 'https://rubygems.org'
ruby "2.1.5"
gem "rmagick", require: 'RMagick'
当我使用docker build .
时:
sudo docker build .
Sending build context to Docker daemon 567.6 MB
Sending build context to Docker daemon
Step 0 : FROM ruby:2.1.5
---> afba1b22768e
Step 1 : RUN apt-get update -qq && apt-get install -y build-essential
---> Using cache
---> 542ba2520fd7
Step 2 : RUN apt-get install -y libpq-dev
---> Using cache
---> 242d31de9101
Step 3 : RUN apt-get install -y libxml2-dev libxslt1-dev
---> Using cache
---> 81fdba39c703
Step 4 : RUN apt-get install -y libqt4-webkit libqt4-dev xvfb
---> Using cache
---> e16c728f5879
Step 5 : RUN apt-get install -y nodejs
---> Using cache
---> 08a676ea038c
Step 6 : RUN apt-get install -y imagemagick libmagickwand-dev
---> Using cache
---> f6911106ff8d
Step 7 : ENV APP_HOME /lescollectionneurs
---> Using cache
---> d4740491742f
Step 8 : RUN mkdir $APP_HOME
---> Using cache
---> f439a8295600
Step 9 : WORKDIR $APP_HOME
---> Using cache
---> 0ffdb5e33df1
Step 10 : ADD Gemfile* $APP_HOME/
---> Using cache
---> 8867a3e40baf
Step 11 : RUN bundle install
---> Running in fd98e604631d
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/.
Resolving dependencies...
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/usr/local/bin/ruby extconf.rb
checking for Ruby version >= 1.8.5... yes
checking for gcc... yes
checking for Magick-config... no
Can't install RMagick 2.13.2. Can't find Magick-config in /usr/local/bundle/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/local/bin/ruby
extconf failed, exit code 1
Gem files will remain installed in /usr/local/bundle/gems/rmagick-2.13.2 for inspection.
Results logged to /usr/local/bundle/extensions/x86_64-linux/2.1.0-static/rmagick-2.13.2/gem_make.out
An error occurred while installing rmagick (2.13.2), and Bundler cannot
continue.
Make sure that `gem install rmagick -v '2.13.2'` succeeds before bundling.
INFO[0014] The command [/bin/sh -c bundle install] returned a non-zero code: 5
它不起作用,因为找不到/ usr / bin /
当我运行sudo docker run -t -i lescollectionneurs /bin/bash
时,我可以这样做:
root@4b015bacf80d:/# apt-get install -y imagemagick libmagickwand-dev
#..... Installing successfully
root@4b015bacf80d:/# /usr/bin/Magick
Magick-config MagickCore-config MagickWand-config
root@4b015bacf80d:/# /usr/bin/Magick-config
Usage: Magick-config [--cflags] [--cppflags] [--exec-prefix] [--ldflags] [--libs] [--prefix] [--version]
Example: gcc `Magick-config --cflags --cppflags` -o core core.c `Magick-config --ldflags --libs`
root@4b015bacf80d:/# gem install rmagick
Fetching: rmagick-2.15.0.gem (100%)
Building native extensions. This could take a while...
Successfully installed rmagick-2.15.0
Parsing documentation for rmagick-2.15.0
Installing ri documentation for rmagick-2.15.0
Done installing documentation for rmagick after 7 seconds
1 gem installed
如您所见,我可以通过打开bash来安装imagemagick。安装后,二进制文件可用,我可以安装rmagick。
为什么docke文件中的结果不一样?如何使用Dockerfile安装rmagick?
答案 0 :(得分:3)
我认为你缺少libmagickcore-dev,这将允许你成功编译rmagick。请尝试以下方法:
RUN apt-get install imagemagick libmagickcore-dev libmagickwand-dev
答案 1 :(得分:3)
宝石版本2.13.4为我解决了这个问题。 https://github.com/docker-library/rails/issues/16#issuecomment-64514330