【问题标题】:Can not install nokogiri gem on dockerfile无法在 dockerfile 上安装 nokogiri gem
【发布时间】:2021-06-12 11:18:16
【问题描述】:

我尝试使用 docker 设置 run rails 项目,所以我构建了一个 dockerfile,如下所示

FROM ruby:2.6.6

RUN apt-get update -qq && apt-get install -y build-essential

# for mysql
RUN apt-get install -y default-libmysqlclient-dev

RUN apt-get install -y git-core zlib1g-dev libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev nodejs yarn

RUN gem install bundler

ENV APP_HOME /myapp
RUN mkdir $APP_HOME
WORKDIR $APP_HOME

ADD Gemfile* $APP_HOME/
RUN bundle install

ADD . $APP_HOME

当我运行docker build . 时,它总是出现如下错误:

 => ERROR [10/11] RUN bundle install                                                                                                                                                                                  1.0s
------                                                                                                                                                                                                                     
 > [10/11] RUN bundle install:                                                                                                                                                                                             
#14 0.850 Resolving dependencies...                                                                                                                                                                                        
#14 0.909 Unable to find a spec satisfying nokogiri (~> 1.8) in the set. Perhaps the                                                                                                                                       
#14 0.909 lockfile is corrupted? Found nokogiri (1.11.2-x86_64-darwin) that did not match
#14 0.909 the current platform.
------
executor failed running [/bin/sh -c bundle install]: exit code: 7

所以请帮帮我。

【问题讨论】:

  • 您的主机不是x86,这与您的 CPU 架构不匹配。我假设你在 Apple M1 上构建它
  • 不,我不使用 Apple M1,我看到的问题是我为 nokogiri gem 安装了libxslt-dev liblzma-dev patch

标签: ruby-on-rails ruby docker nokogiri


【解决方案1】:

我刚刚更改了我的 Dockerfile,它对我有用

FROM ruby:2.6.6

RUN apt-get update -qq && apt-get install -y build-essential
# for mysql
RUN apt-get install -y default-libmysqlclient-dev

RUN apt-get install -y libxslt-dev liblzma-dev patch git-core zlib1g-dev libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev nodejs yarn

RUN gem install bundler
RUN gem install nokogiri --platform=ruby

ENV APP_HOME /myapp
RUN mkdir $APP_HOME
WORKDIR $APP_HOME

ADD docker_app/Gemfile* $APP_HOME/
# RUN bundle config build.nokogiri --use-system-libraries
RUN bundle install

ADD docker_app/. $APP_HOME

【讨论】:

    猜你喜欢
    • 2015-02-14
    • 2016-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-18
    • 2014-01-01
    • 2014-06-17
    • 1970-01-01
    相关资源
    最近更新 更多