我创建了一个虚拟应用程序
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/