docker-alpine: Unable to install ruby gem 'nokogiri'
Hi, I am using base image of gliderlabs/alpine:3.1, and found that not able to instal ruby gems nokogiri.
My Dockerfile
RUN apk add --update \
bash \
ca-certificates \
libxml2 \
libxslt \
gcc \
ruby \
ruby-bundler \
ruby-dev \
nodejs \
mysql-client \
imagemagick \
nginx \
&& rm -rf /var/cache/apk/* \
&& adduser -D app \
&& gem install bundler --no-document \
&& gem install rails nokogiri \
&& npm install -g react-tools babel
As I want to install nokogiri, following error shows:
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.>
/usr/bin/ruby extconf.rb
Building nokogiri using packaged libraries.
-----
libiconv is missing. please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.
-----
*** 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/bin/ruby
--help
--clean
--use-system-libraries
--enable-static
--disable-static
--with-zlib-dir
--without-zlib-dir
--with-zlib-include
--without-zlib-include=${zlib-dir}/include
--with-zlib-lib
--without-zlib-lib=${zlib-dir}/lib
--enable-cross-build
--disable-cross-build
extconf failed, exit code 1
Gem files will remain installed in /home/app/webapp/vendor/bundle/ruby/2.1.0/gems/nokogiri-1.6.3.1 for inspection.
Results logged to /home/app/webapp/vendor/bundle/ruby/2.1.0/extensions/x86_64-linux/2.1.0/nokogiri-1.6.3.1/gem_make.out
An error occurred while installing nokogiri (1.6.3.1), and Bundler cannot
continue.
Is there any way to avoid this?
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 2
- Comments: 22 (2 by maintainers)
Commits related to this issue
- Remove config no longer necessary More Info https://github.com/gliderlabs/docker-alpine/issues/53 — committed to bitzesty/qae by theharq 8 years ago
- Fix issue with nokogiri https://github.com/gliderlabs/docker-alpine/issues/53 — committed to mdouchement/breizhtrip by deleted user 8 years ago
- Fix issue with nokogiri https://github.com/gliderlabs/docker-alpine/issues/53 — committed to mdouchement/breizhtrip by deleted user 8 years ago
- fix docker build Nokogiri >= 1.6.8 doesn't need the `--use-system-libraries` flag any longer to build properly. Source: https://github.com/gliderlabs/docker-alpine/issues/53 — committed to klausmeyer/docker-registry-browser by klausmeyer 8 years ago
- Remove --use-system-libraries Building this Docker container was failing as --use-system-libraries is no more necessary since nokogiri 1.6.8. Per [this GitHub discussion](https://github.com/gliderla... — committed to ojacques/html-proofer-docker by ojacques 8 years ago
- Removing --use-system-libraries REF: https://github.com/gliderlabs/docker-alpine/issues/53 — committed to parafuzo/ruby-base by deleted user 8 years ago
- Follow suggestions from [here](https://github.com/gliderlabs/docker-alpine/issues/53) — committed to mimimalizam/debugging-ruby-nokogiri by mimimalizam 7 years ago
Thanks @joffotron and @mattaitchison, this fixed it for me:
Adding libxml2-dev libxslt-dev to apk add fixed it for me…
nokogiri now bundles its own libxml2, which doesn’t compile on alpine (looks like a pthreads thing maybe?). You can get it to use the libxml2(-dev) package on Alpine by:
or
Hopefully this helps someone else looking for help.
As of nokogiri 1.6.8, the
--use-system-librarieswork-around is unnecessary.In my case
RUN apk update && apk add build-basewas enough to install nokogiri 1.8.2 because:source: https://github.com/sparklemotion/nokogiri#requirements
Thanks @ruudud my build was actually failing when I used
--use-system-librariesand I needed to remove that in order to have succesful build.This worked for me,
Here is the reference Installing Nokogiri
Cleaner version of Dockerfile for nokogiri.
Update: @kylev add document for this issue. Refer to https://github.com/gliderlabs/docker-alpine/issues/53#issuecomment-532467114
Hi, (caveat - beginner docker user), I have managed to successfully install nokogiri on alpine 3.2 by using the package name
ruby-nokogiri(see packages listing). That is, via Dockerfile:maybe that helps?
Building native extensions requires certain system libraries and the
build-basepackage.You can see how
ruby-nokogiriis built and what dependencies are required by looking at itsAPKBUILDfile. View HereFeel free to reopen this issue if you are still having problems.
I added additional documentation (as @gr1d99 mentioned) in sparklemotion/nokogiri.org#23
This works for me
Basically