簡體   English   中英

Dockerfile cmd返回Yarn完整性錯誤,但Docker運行正常

[英]Dockerfile cmd returns Yarn integrity error but Docker run works fine

我正在嘗試讓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返回錯誤。

您可以將您的Dockerfile + Dockerfile docker-compose.yml該文件進行比較,看看是否存在任何區別(例如使用RUN yarn install --check-files ),這會使錯誤消息消失。

Dirk de Kok的使用Webpacker和Docker運行Rails應用程序 ”中使用了另一個示例( Dockerfile + docker docker-compose.yml

在這兩種情況下,應用程序都是通過docker-compose up
正如您所遵循的那樣,它們遵循了rails/webpacker問題1568的建議(關於config/environments/development.rb config.webpacker.check_yarn_integrity = false

今天有效。 無需更改代碼,而是決定可以正常工作。 我嘗試運行docker-compose run web rm -rf /重新開始,但是它忽略了該命令,然后開始工作。 這就是生活。 @vonc謝謝您的努力,我將給予您獎勵。

編輯:它返回。 這次我用

docker rm $(docker ps -a -q)

警告:這會破壞您的所有容器。 如果卷中有數據,請不要使用它。

問題的原因是嘗試創建Dockerfile,並且撰寫沒有清除卷的一部分。 docker-compose rundocker-compose up不同docker-compose up因為run在docker卷的頂部創建了一個新層來執行命令,本質上是創建了一個新容器。 Docker本身未能將更改應用於舊層。

使config.webpacker.check_yarn_integrity = false不是一個好主意。

由於版本不兼容而發生。

嘗試

rails webpacker:install

它應該可以解決您的問題。


如果不嘗試

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM