Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to install the gem "rmagick" with docker

I have this 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

And this Gemfile :

source 'https://rubygems.org'

ruby "2.1.5"

gem "rmagick", require: 'RMagick'

When I user 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

It does not work because it cannot find /usr/bin/

When I run sudo docker run -t -i lescollectionneurs /bin/bash, I can do this :

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

As you can see, I can install imagemagick by opening the bash. After the installation , the binary file is available and I can install rmagick.

Why the result is not the same in the docke file ? How can I install rmagick using the Dockerfile ?

like image 995
Dougui Avatar asked May 18 '15 21:05

Dougui


2 Answers

I think you are missing libmagickcore-dev which will allow you to successfully compile rmagick. Try the following:

RUN apt-get install imagemagick libmagickcore-dev libmagickwand-dev
like image 134
errata Avatar answered Oct 13 '22 01:10

errata


Version 2.13.4 of the gem has fixed this problem for me. https://github.com/docker-library/rails/issues/16#issuecomment-64514330

like image 23
Heiko Avatar answered Oct 12 '22 23:10

Heiko