代码之家  ›  专栏  ›  技术社区  ›  Michael Durrant

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

  •  0
  • Michael Durrant  · 技术社区  · 5 年前

    我的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
    
    1 回复  |  直到 5 年前
        1
  •  1
  •   Michael Durrant    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

        2
  •  0
  •   tee_zed_0    4 年前

    阿尔卑斯山

    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