【问题标题】:Dockerfile cmd returns Yarn integrity error but Docker run works fineDockerfile cmd 返回 Yarn 完整性错误,但 Docker 运行正常
【发布时间】:2019-05-14 14:39:29
【问题描述】:

我正在尝试让 Rails 6 应用程序在 Docker 中运行。从 dockerfile 执行命令 rails server 时,出现错误。

remote: web_1_a59d968487d2 | warning Integrity check: System parameters don't match
remote: web_1_a59d968487d2 | error Integrity check failed
remote: web_1_a59d968487d2 | error Found 1 errors.
remote: web_1_a59d968487d2 | 
remote: web_1_a59d968487d2 | 
remote: web_1_a59d968487d2 | ========================================
remote: web_1_a59d968487d2 |   Your Yarn packages are out of date!
remote: web_1_a59d968487d2 |   Please run `yarn install --check-files` to update.
remote: web_1_a59d968487d2 | ========================================
remote: web_1_a59d968487d2 | 
remote: web_1_a59d968487d2 | 
remote: web_1_a59d968487d2 | To disable this check, please change `check_yarn_integrity`
remote: web_1_a59d968487d2 | to `false` in your webpacker config file (config/webpacker.yml).
remote: web_1_a59d968487d2 | 
remote: web_1_a59d968487d2 | 
remote: web_1_a59d968487d2 | yarn check v1.16.0
remote: web_1_a59d968487d2 | info Visit https://yarnpkg.com/en/docs/cli/check for documentation about this command.

在我的 config/webpacker.yml 文件中有这一行:

development:
  <<: *default
  check_yarn_integrity: false

在我的 config/environments/development.rb 中:

  config.webpacker.check_yarn_integrity = false

我还在构建我的 node_modules 作为 docker setup (Dockerfile) 的一部分:

FROM ruby:2.6.3
RUN apt-get update && apt-get install apt-transport-https
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update -qq && apt-get install -y nodejs yarn
RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle install

COPY . /myapp
RUN rm -Rf node_modules/
RUN rm yarn.lock
RUN yarn install

ENV RAILS_ENV=development
EXPOSE 3000

# Start the main process.
CMD ["rails", "server", "-b", "0.0.0.0"]

运行docker-compose run web rails s -b 0.0.0.0 有效。

运行 docker-compose up --build web 返回错误。

【问题讨论】:

标签: ruby-on-rails docker yarnpkg


【解决方案1】:

您可以将您的Dockerfile+docker-compose.ymlthis one 进行比较,看看是否有任何差异(例如使用RUN yarn install --check-files)会使错误消息消失。

另一个例子(Dockerfile+docker-compose.yml)用在Dirk de Kok

的“Running a Rails app with Webpacker and Docker”中

在这两种情况下,应用程序都以docker-compose up 启动。
他们也像你一样遵循了rails/webpacker issue 1568 的建议(关于config/environments/development.rb 中的config.webpacker.check_yarn_integrity = false

【讨论】:

  • 您在 docker compose 中缺少一个连字符,它希望我包含 6 个字符进行编辑。我找不到其他任何东西可以使答案更好,所以我想知道您是否可以添加连字符。 docker-compose
  • @AndyGauge 当然,我已经相应地编辑了答案。
【解决方案2】:

今天成功了。没有更改任何代码,它只是决定工作。我尝试运行 docker-compose run web rm -rf / 重新开始,但它忽略了该命令然后开始工作。这就是生活。 @vonc 谢谢你的努力,我会奖励你的。

编辑:它返回了。这次我用

修复了它
docker rm $(docker ps -a -q)

警告:这会破坏您的所有容器。如果您的卷中有数据,请不要使用它。

问题的原因是尝试创建 Dockerfile,而撰写没有清除卷的一层。 docker-compose rundocker-compose up 不同,因为 run 在 docker 卷之上创建了一个新层来执行命令,本质上是创建一个新容器。 Docker 本身未能将更改应用到旧层。

【讨论】:

    【解决方案3】:

    制作config.webpacker.check_yarn_integrity = false 不是一个好主意。

    版本不兼容造成的。

    试试

    rails webpacker:install
    

    应该可以解决你的问题。


    如果不尝试

    $ rm yarn.lock
    $ yarn cache clean
    $ yarn install
    

    【讨论】:

    • 是的,我束手无策,试图弄清楚发生了什么,但这与 rails 和 yarn 无关,这是 docker 中的一个错误。在我发布到 SO 的时间里,我已经完成了这些步骤。我确实希望这对遇到类似问题的人有所帮助。
    猜你喜欢
    • 2020-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-10
    • 1970-01-01
    • 2020-08-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多