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



使用 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

将以下行添加到 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 的发现。

对于高山

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

最新更新