Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker sh: 1: yarn: not found

I created a dummy app

Rails new myapp --skip-test

Then added a Dockerfile to it like this:

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

whenever I build an image

docker build . # let's say the image id will be b2b0674325d1

Then I try to run the server sudo docker run -p 3000:3000 b2b0674325d1 bin/rails s -b 0.0.0.0

I get this error

=> 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).

Any idea?

like image 251
medBouzid Avatar asked Oct 16 '22 06:10

medBouzid


1 Answers

I just came across this issue. You need to install yarn and install the node_modules folder required by a Rails application. The --check-files error is due to a mismatch between your package.json file and your missing yarn.lock file. https://classic.yarnpkg.com/en/docs/cli/check

Adding this to your Dockerfile will install yarn and the missing node_modules in your rails app

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

like image 71
Alan Eduardo Covarrubias Avatar answered Oct 18 '22 14:10

Alan Eduardo Covarrubias