Docker - ruby ,nokogiri - 安装nokogiri时出错(1.10.2),

问题描述 投票:0回答:1

使用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
ruby docker dockerfile nokogiri
1个回答
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的发现。

© www.soinside.com 2019 - 2024. All rights reserved.