Docker Won't Install Libxml
source link: https://fuzzyblog.io/blog/docker/2017/09/21/docker-won-t-install-libxml.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Docker Won't Install Libxml
Sep 21, 2017
One of the most vexing situations in any type of development is when something that you swear you've done literally hundreds of times fails to work – at all. It always turns out to be that what you're doing is 99.995% the same as something previous – and .005% different. Last night I went to do a docker-compose build on a new application using my standard stack of Ruby, Rails, Mechanize and the like and I got this, well, crap:
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /usr/local/bundle/gems/libxml-ruby-3.0.0/ext/libxml
/usr/local/bin/ruby -r ./siteconf20170920-5-mpa6ar.rb extconf.rb
checking for libxml/xmlversion.h in
*** 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:
extconf failure: need libxml2.
Install the library or try one of the following options to extconf.rb:
To see why this extension failed to compile, please check the mkmf.log which can
be found here:
I can't get to the mkmf.log file since that's I think done with a container since its clearly linux not osx.
No clue why this is happening since I use this same damn gem everwhere
There was also this info
Gem files will remain installed in /usr/local/bundle/gems/libxml-ruby-3.0.0 for
Results logged to
An error occurred while installing libxml-ruby (3.0.0), and Bundler cannot
Make sure that `gem install libxml-ruby -v '3.0.0'` succeeds before bundling.
ERROR: Service 'web' failed to build: The command '/bin/sh -c bundle install --binstubs' returned a non-zero code: 5
One of the major reasons I got into Docker in the first place was to get away from this kind of crap! Gem builds, particularly where libxml is involved, well, suck. I spent close to two hours last night tweaking things, updating libraries and such and it was a complete and utter failure. I even installed Docker on a brand new dev machine and got the exact same result.
RUN apk update && apk add build-base nodejs mariadb-dev tzdata git
RUN apk update && apk add build-base nodejs mariadb-dev tzdata git libxml2-dev
This was hugely surprising to me because according to github, I haven't touched my Dockerfile in 4 months ever since my Docker buddy and guru, Nick, helped me set it up. My docker-compose file, however, was just modified 22 days ago. As docker-compose has become ever more important in the Docker world, the basic Dockerfile is something you touch less and less – apparently until something bites you in the proverbial arse.
And Here's Why this Happened
My normal use of libxml, for the past decade or so, is always tied straight to Ruby's Mechanize gem which I've had running correctly under Docker for the past six months. And that's why this was so, so surprising to me. The mistake that I made was that earlier today I had added twilio-ruby to my Gemfile and apparently twilio-ruby has different nokogiri dependencies than Mechanize which caused the Dockerfile to need libxml2-dev. Digging into the twilio-ruby issues, I found this issue which seems to address it.
My buddy Nick, mentioned above, talks about this on his blog.
Aggregate valuable and interesting links.
Joyk means Joy of geeK