ruby-on-rails - docker sh : 1: yarn: not found

标签 ruby-on-rails docker

我创建了一个虚拟应用程序

Rails new myapp --skip-test

然后像这样添加一个 Dockerfile 到它:
FROM ruby:2.6

RUN apt-get update -yqq

RUN apt-get install -yqq --no-install-recommends nodejs

COPY . /usr/src/app

WORKDIR /usr/src/app

RUN bundle install

每当我构建图像时
docker build . # let's say the image id will be b2b0674325d1

然后我尝试运行服务器 sudo docker run -p 3000:3000 b2b0674325d1 bin/rails s -b 0.0.0.0
我收到这个错误
=> Booting Puma
=> Rails 6.0.2.1 application starting in development 
=> Run `rails server --help` for more startup options
sh: 1: yarn: not found


========================================
  Your Yarn packages are out of date!
  Please run `yarn install --check-files` to update.
========================================


To disable this check, please change `check_yarn_integrity`
to `false` in your webpacker config file (config/webpacker.yml).

任何的想法?

最佳答案

我刚刚遇到这个问题。
您需要安装 yarn 并安装 Rails 应用程序所需的 node_modules 文件夹。
--check-files 错误是由于 package.json 文件和丢失的 yarn.lock 文件不匹配造成的。
https://classic.yarnpkg.com/en/docs/cli/check
将此添加到您的 Dockerfile 将在您的 Rails 应用程序中安装 yarn 和缺少的 node_modules

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 yarn
RUN yarn install

While we are on the subject of lockfiles, I came across an issue when trying to run my app in development. Here is an article that I found useful https://nickjanetakis.com/blog/dealing-with-lock-files-when-using-ruby-node-and-elixir-with-docker

关于ruby-on-rails - docker sh : 1: yarn: not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60249220/

相关文章:

mysql - Docker ps -a 不显示已停止的 mysql 客户端运行容器

jquery - Ruby on Rails 实时搜索(过滤)

docker - 无法访问 qbittorrent docker webui

ruby-on-rails - 按父属性对子项进行分组

ruby-on-rails - Rails - 在 Javascript 中内联 scss 文件

docker - 在运行时从主机引用 “env-file”中的env变量传递给docker镜像

azure - 在azure云实例上启动容器时有没有办法指定主机名

Docker 脚本首次运行时未连接(sql 转储)

ruby-on-rails - 雾、Amazon S3 和 Carrierwave Rails 问题

ruby-on-rails - 如何使用 nokogiri 和 ruby​​zip 编辑 docx