rmagick: Can't install rmagick in Docker Alpine

Our containers run on Docker Alpine ruby:2.5.3-alpine.

I installed ImageMagick but found no way to install this gem. This looks similar to #282 but Alpine has so many things(software) left out compared to CentOS.

Error message:

Fetching rmagick 4.0.0
Installing rmagick 4.0.0 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /usr/local/bundle/gems/rmagick-4.0.0/ext/RMagick
/usr/local/bin/ruby -I /usr/local/lib/ruby/site_ruby/2.5.0 -r
./siteconf20191031-56-1elb4ic.rb extconf.rb
checking for brew... no
checking for pacman... no
checking for gcc... yes
checking for pkg-config... yes


ERROR: Can't install RMagick 4.0.0. Can't find ImageMagick with
pkg-config


*** 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_BASE_NAME)

To see why this extension failed to compile, please check the mkmf.log which can
be found here:

  /usr/local/bundle/extensions/x86_64-linux/2.5.0/rmagick-4.0.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /usr/local/bundle/gems/rmagick-4.0.0 for
inspection.
Results logged to
/usr/local/bundle/extensions/x86_64-linux/2.5.0/rmagick-4.0.0/gem_make.out

An error occurred while installing rmagick (4.0.0), and Bundler cannot continue.
Make sure that `gem install rmagick -v '4.0.0' --source 'https://rubygems.org/'`
succeeds before bundling.

In Gemfile:
  rmagick

This isn’t maybe the place but wanted to add the issue for the record as I didn’t find a way to install in Docker Alpine images.

Installing pkg-config in Alpine wasn’t possible as well.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 2
  • Comments: 15 (9 by maintainers)

Most upvoted comments

Imagemagick7 is not yet compatible with rmagick. So installing Imagemagick6 worked for me.

FROM ruby:2.5.3-alpine3.8

WORKDIR /tmp

RUN apk add --update --no-cache build-base imagemagick6 imagemagick6-c++ \
    imagemagick6-dev imagemagick6-libs

RUN gem install rmagick

pkg-config is not correctly listing for installed packages on AlpineLinux. RMagick depends on pkg-config. Unfortunately this cannot be solved, so can you report this to proper community ?

Dockerfile

FROM alpine:latest

RUN apk update && apk upgrade && apk add pkgconfig imagemagick
RUN pkg-config --list-all

Result

Sending build context to Docker daemon  4.096kB
Step 1/3 : FROM alpine:latest
 ---> cc0abc535e36
Step 2/3 : RUN apk update && apk upgrade && apk add imagemagick
 ---> Running in bdfaa88cb7b7
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/x86_64/APKINDEX.tar.gz
v3.11.2-51-g7cf8ea7952 [http://dl-cdn.alpinelinux.org/alpine/v3.11/main]
v3.11.2-53-ged2c5b48f5 [http://dl-cdn.alpinelinux.org/alpine/v3.11/community]
OK: 11261 distinct packages available
(1/2) Upgrading libcrypto1.1 (1.1.1d-r2 -> 1.1.1d-r3)
(2/2) Upgrading libssl1.1 (1.1.1d-r2 -> 1.1.1d-r3)
OK: 6 MiB in 14 packages
(1/56) Installing libxau (1.0.9-r0)
(2/56) Installing libbsd (0.10.0-r0)
(3/56) Installing libxdmcp (1.1.3-r0)
(4/56) Installing libxcb (1.13.1-r0)
(5/56) Installing libx11 (1.6.9-r0)
(6/56) Installing libxext (1.3.4-r0)
(7/56) Installing libbz2 (1.0.8-r1)
(8/56) Installing expat (2.2.9-r1)
(9/56) Installing libpng (1.6.37-r1)
(10/56) Installing freetype (2.10.1-r0)
(11/56) Installing libuuid (2.34-r1)
(12/56) Installing fontconfig (2.13.1-r2)
(13/56) Installing lcms2 (2.9-r1)
(14/56) Installing libltdl (2.4.6-r7)
(15/56) Installing xz-libs (5.2.4-r0)
(16/56) Installing libxml2 (2.9.10-r1)
(17/56) Installing imagemagick-libs (7.0.9.7-r0)
(18/56) Installing libxrender (0.9.10-r3)
(19/56) Installing pixman (0.38.4-r0)
(20/56) Installing cairo (1.16.0-r2)
(21/56) Installing libffi (3.2.1-r6)
(22/56) Installing libintl (0.20.1-r2)
(23/56) Installing libblkid (2.34-r1)
(24/56) Installing libmount (2.34-r1)
(25/56) Installing pcre (8.43-r0)
(26/56) Installing glib (2.62.4-r0)
(27/56) Installing dbus-libs (1.12.16-r2)
(28/56) Installing avahi-libs (0.7-r4)
(29/56) Installing gmp (6.1.2-r1)
(30/56) Installing nettle (3.5.1-r0)
(31/56) Installing p11-kit (0.23.18.1-r0)
(32/56) Installing libtasn1 (4.15.0-r0)
(33/56) Installing libunistring (0.9.10-r0)
(34/56) Installing gnutls (3.6.10-r0)
(35/56) Installing cups-libs (2.2.12-r1)
(36/56) Installing jbig2dec (0.17-r0)
(37/56) Installing libjpeg-turbo (2.0.4-r0)
(38/56) Installing tiff (4.1.0-r0)
(39/56) Installing ghostscript (9.50-r0)
(40/56) Installing libgcc (9.2.0-r3)
(41/56) Installing libstdc++ (9.2.0-r3)
(42/56) Installing libde265 (1.0.3-r0)
(43/56) Installing x265-libs (3.2.1-r0)
(44/56) Installing libheif (1.6.0-r0)
(45/56) Installing libcroco (0.6.13-r1)
(46/56) Installing pkgconf (1.6.3-r0)
(47/56) Installing shared-mime-info (1.15-r0)
(48/56) Installing gdk-pixbuf (2.40.0-r0)
(49/56) Installing libxft (2.3.3-r0)
(50/56) Installing fribidi (1.0.8-r0)
(51/56) Installing graphite2 (1.3.13-r1)
(52/56) Installing harfbuzz (2.6.4-r0)
(53/56) Installing pango (1.44.7-r0)
(54/56) Installing librsvg (2.46.4-r0)
(55/56) Installing libwebp (1.0.3-r0)
(56/56) Installing imagemagick (7.0.9.7-r0)
Executing busybox-1.31.1-r8.trigger
Executing fontconfig-2.13.1-r2.trigger
Executing shared-mime-info-1.15-r0.trigger
Executing gdk-pixbuf-2.40.0-r0.trigger
OK: 101 MiB in 70 packages
Removing intermediate container bdfaa88cb7b7
 ---> 44ad583f679e
Step 3/3 : RUN pkg-config --list-all
 ---> Running in 27054271d973
shared-mime-info               shared-mime-info - Freedesktop common MIME database
Removing intermediate container 27054271d973
 ---> 409008d1af85
Successfully built 409008d1af85
Successfully tagged rmagick-alpine:latest

I think It is tough because there is no header files of ImageMagick within Alpine package.

$ docker run --rm -it rmagick-alpine
# find /usr -name "*Magick*"
/usr/share/ImageMagick-7
/usr/lib/libMagickCore-7.Q16HDRI.so.7
/usr/lib/libMagickWand-7.Q16HDRI.so.7.0.0
/usr/lib/libMagickCore-7.Q16HDRI.so.7.0.0
/usr/lib/libMagickWand-7.Q16HDRI.so.7
/usr/lib/ImageMagick-7.0.9

If you want to use Alpine, I think you need to build ImageMagick by yourself from source.

Thanks for the followup @cesc1989. Can you also provide the output from the mkmf.log file mentioned?

@cesc1989 were you able to install the latest version of RMagick?

@cesc1989 It seems RMagick can’t find an ImageMagick installation. Can you verify which version of ImageMagick you have installed with convert --version or identify --version? Also, please note, RMagick 4.0 and before do not support ImageMagick >= 7. If you have ImageMagick 7, you can try our 4.1.0.rc2 gem.