Docker-ruby,nokogiri-安装nokogiri(1.10.2)时发生错误,

时间:2019-04-14 18:33:23

标签: ruby docker dockerfile nokogiri

使用docker尝试构建映像,但是由于nokogiri gem问题,我在捆绑时收到上述错误

我的Docker文件是

RUN apt update
RUN apt install -y ruby
RUN gem install bundler
RUN cd /usr/src/app
WORKDIR /web
ADD Gemfile /web/
RUN bundle

但是,当我RUN bundle结尾时,^出现以下错误:

...
Fetching mini_portile2 2.4.0                                                                                                                                              
Installing mini_portile2 2.4.0                                                                                                                                            
Fetching nokogiri 1.10.2                                                                                                                                                  
Installing nokogiri 1.10.2 with native extensions                                                                                                                         
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.                                                                                                        

    current directory: /var/lib/gems/2.5.0/gems/nokogiri-1.10.2/ext/nokogiri                                                                                              
/usr/bin/ruby2.5 -r ./siteconf20190414-8-1rrc2i8.rb extconf.rb                                                                                                            
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h                                                                                                  

extconf failed, exit code 1                                                                                                                                               

Gem files will remain installed in /var/lib/gems/2.5.0/gems/nokogiri-1.10.2 for                                                                                           
inspection.                                                                                                                                                               
Results logged to                                                                                                                                                         
/var/lib/gems/2.5.0/extensions/x86_64-linux/2.5.0/nokogiri-1.10.2/gem_make.out                                                                                            

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

In Gemfile:                                                                                                                                                               
  capybara was resolved to 3.16.2, which depends on
    xpath was resolved to 3.2.0, which depends on
      nokogiri
The command '/bin/sh -c bundle' returned a non-zero code: 5

2 个答案:

答案 0 :(得分:0)

将以下行添加到Dockerfile中,它将处理依赖项

RUN apt install -y build-essential patch ruby-dev zlib1g-dev liblzma-dev

RUN bundle命令之前

然后再次运行构建

docker build -t dock .

...
Fetching nokogiri 1.10.2  
Installing nokogiri 1.10.2 with native extensions  
Fetching rack 2.0.7  
Installing rack 2.0.7  
...
Bundle complete! 7 Gemfile dependencies, 33 gems now installed.  
Use `bundle info [gemname]` to see where a bundled gem is installed.  
Removing intermediate container 146ce309d0a5           
 ---> cd36c7c1e577
Successfully built cd36c7c1e577
Successfully tagged dock:latest

...

感谢https://nokogiri.org/tutorials/installing_nokogiri.html的发现。

答案 1 :(得分:0)

对于高山

RUN set -x \   && apk upgrade --no-cache \    && apk add --no-cache
--virtual build-dependencies \
    build-base \   && apk add --no-cache \
    libxml2-dev \
    libxslt-dev \   && gem install nokogiri \
    -- --use-system-libraries \
    --with-xml2-config=/usr/bin/xml2-config \
    --with-xslt-config=/usr/bin/xslt-config \   && apk del build-dependencies