Dockerfile cmd返回Yarn完整性错误,但Docker运行正常

时间:2019-05-14 14:39:29

标签: ruby-on-rails docker yarnpkg

我试图让Rails 6应用程序在Docker中运行。从dockerfile执行命令rails服务器时,出现错误。

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

我也在docker设置(Dockerfile)中构建我的node_modules:

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返回错误。

3 个答案:

答案 0 :(得分:1)

  

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

由于版本不兼容而发生。

尝试

rails webpacker:install

它应该可以解决您的问题。


如果不尝试

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

答案 1 :(得分:0)

您可以将Dockerfile + docker-compose.ymlthis one进行比较,看看是否存在不同之处(例如使用RUN yarn install --check-files),这会使错误消息消失。

Dockerfile 中的“ docker-compose.yml ”中使用了另一个示例(Running a Rails app with Webpacker and Docker + Dirk de Kok

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

答案 2 :(得分:0)

今天有效。无需更改代码,而是决定可以正常工作。我尝试运行docker-compose run web rm -rf /重新开始,但是它忽略了该命令,然后开始工作。这就是生活。 @vonc感谢您的努力,我会给您奖励。

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

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

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

问题的原因是尝试创建Dockerfile,并且撰写未清除卷的一部分。 docker-compose rundocker-compose up不同,因为run在docker卷的顶部创建了一个新层来执行命令,实际上是创建了一个新容器。 Docker本身未能将更改应用于旧层。