Docker not installing yarn

Error running rails: yarn not installed
I’m trying to run docker like . the following.
but then even if i install yarn it still doesn’t work.


FROM rails:on-build
CMD [ "rails" , "s" , "-b" , "" , "-p", "3000" ]


FROM ruby:2.6.2
RUN apt-get update -y && apt-get install -y build-essential libpq-dev nodejs sqlite3
ONBUILD COPY app /opt/app
ONBUILD RUN bundle install
ONBUILD RUN rake db:migrate
ONBUILD RUN rake db:seed

docker-machine create -d virtualbox Char
eval $(docker-machine env Char)
docker build -t rails:on-build . #this runs ok
docker build -t "thisdir:Dockerfile" . #this command triggers the error


Sending build context to Docker daemon  3.584kB
Step 1/4 : FROM rails:on-build
# Executing 6 build triggers
 ---> Using cache
 ---> Running in 7bfd996846cd
      create  Rakefile
      create  .ruby-version
      create  .gitignore
      create  Gemfile
         run  git init from "."
Initialized empty Git repository in /opt/app/.git/
      create  package.json
      create  app
      create  app/assets/config/manifest.js
      create  app/assets/stylesheets/application.css
      create  app/channels/application_cable/channel.rb
      create  app/channels/application_cable/connection.rb
      create  app/controllers/application_controller.rb
      create  app/helpers/application_helper.rb
      create  app/javascript/channels/consumer.js
      create  app/javascript/channels/index.js
      create  app/javascript/packs/application.js
      create  app/jobs/application_job.rb
      create  app/mailers/application_mailer.rb
      create  app/models/application_record.rb
      create  app/views/layouts/application.html.erb
      create  app/views/layouts/mailer.html.erb
      create  app/views/layouts/mailer.text.erb
      create  app/assets/images/.keep
      create  app/controllers/concerns/.keep
      create  app/models/concerns/.keep
      create  bin
      create  bin/rails
      create  bin/rake
      create  bin/setup
      create  bin/yarn
      create  config
      create  config/routes.rb
      create  config/application.rb
      create  config/environment.rb
      create  config/cable.yml
      create  config/puma.rb
      create  config/spring.rb
      create  config/storage.yml
      create  config/environments
      create  config/environments/development.rb
      create  config/environments/production.rb
      create  config/environments/test.rb
      create  config/initializers
      create  config/initializers/application_controller_renderer.rb
      create  config/initializers/assets.rb
      create  config/initializers/backtrace_silencers.rb
      create  config/initializers/content_security_policy.rb
      create  config/initializers/cookies_serializer.rb
      create  config/initializers/cors.rb
      create  config/initializers/filter_parameter_logging.rb
      create  config/initializers/inflections.rb
      create  config/initializers/mime_types.rb
      create  config/initializers/new_framework_defaults_6_0.rb
      create  config/initializers/wrap_parameters.rb
      create  config/locales
      create  config/locales/en.yml
      create  config/master.key
      append  .gitignore
      create  config/boot.rb
      create  config/database.yml
      create  db
      create  db/seeds.rb
      create  lib
      create  lib/tasks
      create  lib/tasks/.keep
      create  lib/assets
      create  lib/assets/.keep
      create  log
      create  log/.keep
      create  public
      create  public/404.html
      create  public/422.html
      create  public/500.html
      create  public/apple-touch-icon-precomposed.png
      create  public/apple-touch-icon.png
      create  public/favicon.ico
      create  public/robots.txt
      create  tmp
      create  tmp/.keep
      create  tmp/pids
      create  tmp/pids/.keep
      create  tmp/cache
      create  tmp/cache/assets
      create  vendor
      create  vendor/.keep
      create  test/fixtures
      create  test/fixtures/.keep
      create  test/fixtures/files
      create  test/fixtures/files/.keep
      create  test/controllers
      create  test/controllers/.keep
      create  test/mailers
      create  test/mailers/.keep
      create  test/models
      create  test/models/.keep
      create  test/helpers
      create  test/helpers/.keep
      create  test/integration
      create  test/integration/.keep
      create  test/channels/application_cable/connection_test.rb
      create  test/test_helper.rb
      create  test/system
      create  test/system/.keep
      create  test/application_system_test_case.rb
      create  storage
      create  storage/.keep
      create  tmp/storage
      create  tmp/storage/.keep
      remove  config/initializers/cors.rb
      remove  config/initializers/new_framework_defaults_6_0.rb
         run  bundle install
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Fetching gem metadata from
Fetching gem metadata from
Resolving dependencies...
Fetching rake 13.0.1
Installing rake 13.0.1
Fetching concurrent-ruby 1.1.5
Installing concurrent-ruby 1.1.5
Fetching i18n 1.7.0
Installing i18n 1.7.0
Fetching minitest 5.13.0
Installing minitest 5.13.0
Fetching thread_safe 0.3.6
Installing thread_safe 0.3.6
Fetching tzinfo 1.2.5
Installing tzinfo 1.2.5
Fetching zeitwerk 2.2.2
Installing zeitwerk 2.2.2
Fetching activesupport
Installing activesupport
Fetching builder 3.2.4
Installing builder 3.2.4
Fetching erubi 1.9.0
Installing erubi 1.9.0
Fetching mini_portile2 2.4.0
Installing mini_portile2 2.4.0
Fetching nokogiri 1.10.7
Installing nokogiri 1.10.7 with native extensions
Fetching rails-dom-testing 2.0.3
Installing rails-dom-testing 2.0.3
Fetching crass 1.0.5
Installing crass 1.0.5
Fetching loofah 2.4.0
Installing loofah 2.4.0
Fetching rails-html-sanitizer 1.3.0
Installing rails-html-sanitizer 1.3.0
Fetching actionview
Installing actionview
Fetching rack 2.0.8
Installing rack 2.0.8
Fetching rack-test 1.1.0
Installing rack-test 1.1.0
Fetching actionpack
Installing actionpack
Fetching nio4r 2.5.2
Installing nio4r 2.5.2 with native extensions
Fetching websocket-extensions 0.1.4
Installing websocket-extensions 0.1.4
Fetching websocket-driver 0.7.1
Installing websocket-driver 0.7.1 with native extensions
Fetching actioncable
Installing actioncable
Fetching globalid 0.4.2
Installing globalid 0.4.2
Fetching activejob
Installing activejob
Fetching activemodel
Installing activemodel
Fetching activerecord
Installing activerecord
Fetching mimemagic 0.3.3
Installing mimemagic 0.3.3
Fetching marcel 0.3.3
Installing marcel 0.3.3
Fetching activestorage
Installing activestorage
Fetching mini_mime 1.0.2
Installing mini_mime 1.0.2
Fetching mail 2.7.1
Installing mail 2.7.1
Fetching actionmailbox
Installing actionmailbox
Fetching actionmailer
Installing actionmailer
Fetching actiontext
Installing actiontext
Fetching public_suffix 4.0.1
Installing public_suffix 4.0.1
Fetching addressable 2.7.0
Installing addressable 2.7.0
Fetching bindex 0.8.1
Installing bindex 0.8.1 with native extensions
Fetching msgpack 1.3.1
Installing msgpack 1.3.1 with native extensions
Fetching bootsnap 1.4.5
Installing bootsnap 1.4.5 with native extensions
Using bundler 2.1.1
Fetching byebug 11.0.1
Installing byebug 11.0.1 with native extensions
Fetching regexp_parser 1.6.0
Installing regexp_parser 1.6.0
Fetching xpath 3.2.0
Installing xpath 3.2.0
Fetching capybara 3.29.0
Installing capybara 3.29.0
Fetching childprocess 3.0.0
Installing childprocess 3.0.0
Fetching ffi 1.11.3
Installing ffi 1.11.3 with native extensions
Fetching jbuilder 2.9.1
Installing jbuilder 2.9.1
Fetching rb-fsevent 0.10.3
Installing rb-fsevent 0.10.3
Fetching rb-inotify 0.10.0
Installing rb-inotify 0.10.0
Fetching ruby_dep 1.5.0
Installing ruby_dep 1.5.0
Fetching listen 3.1.5
Installing listen 3.1.5
Fetching method_source 0.9.2
Installing method_source 0.9.2
Fetching puma 4.3.1
Installing puma 4.3.1 with native extensions
Fetching rack-proxy 0.6.5
Installing rack-proxy 0.6.5
Fetching thor 1.0.1
Installing thor 1.0.1
Fetching railties
Installing railties
Fetching sprockets 4.0.0
Installing sprockets 4.0.0
Fetching sprockets-rails 3.2.1
Installing sprockets-rails 3.2.1
Fetching rails
Installing rails
Fetching rubyzip 2.0.0
Installing rubyzip 2.0.0
Fetching sassc 2.2.1
Installing sassc 2.2.1 with native extensions
Fetching tilt 2.0.10
Installing tilt 2.0.10
Fetching sassc-rails 2.1.2
Installing sassc-rails 2.1.2
Fetching sass-rails 6.0.0
Installing sass-rails 6.0.0
Fetching selenium-webdriver 3.142.6
Installing selenium-webdriver 3.142.6
Fetching spring 2.1.0
Installing spring 2.1.0
Fetching spring-watcher-listen 2.0.1
Installing spring-watcher-listen 2.0.1
Fetching sqlite3 1.4.2
Installing sqlite3 1.4.2 with native extensions
Fetching turbolinks-source 5.2.0
Installing turbolinks-source 5.2.0
Fetching turbolinks 5.2.1
Installing turbolinks 5.2.1
Fetching web-console 4.0.1
Installing web-console 4.0.1
Fetching webdrivers 4.1.3
Installing webdrivers 4.1.3
Fetching webpacker 4.2.2
Installing webpacker 4.2.2
Bundle complete! 17 Gemfile dependencies, 75 gems now installed.
Bundled gems are installed into `/usr/local/bundle`
         run  bundle binstubs bundler
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
         run  bundle exec spring binstub --all
/usr/local/lib/ruby/2.6.0/bundler/vendor/fileutils/lib/fileutils.rb:1186: warning: already initialized constant Bundler::FileUtils::Entry_::S_IF_DOOR
/usr/local/bundle/gems/bundler-2.1.1/lib/bundler/vendor/fileutils/lib/fileutils.rb:1284: warning: previous definition of S_IF_DOOR was here
/usr/local/lib/ruby/2.6.0/bundler/vendor/fileutils/lib/fileutils.rb:1444: warning: already initialized constant Bundler::FileUtils::Entry_::DIRECTORY_TERM
/usr/local/bundle/gems/bundler-2.1.1/lib/bundler/vendor/fileutils/lib/fileutils.rb:1568: warning: previous definition of DIRECTORY_TERM was here
/usr/local/lib/ruby/2.6.0/bundler/vendor/fileutils/lib/fileutils.rb:1499: warning: already initialized constant Bundler::FileUtils::OPT_TABLE
/usr/local/bundle/gems/bundler-2.1.1/lib/bundler/vendor/fileutils/lib/fileutils.rb:1626: warning: previous definition of OPT_TABLE was here
/usr/local/lib/ruby/2.6.0/bundler/vendor/fileutils/lib/fileutils.rb:1553: warning: already initialized constant Bundler::FileUtils::LOW_METHODS
/usr/local/bundle/gems/bundler-2.1.1/lib/bundler/vendor/fileutils/lib/fileutils.rb:1685: warning: previous definition of LOW_METHODS was here
/usr/local/lib/ruby/2.6.0/bundler/vendor/fileutils/lib/fileutils.rb:1560: warning: already initialized constant Bundler::FileUtils::METHODS
/usr/local/bundle/gems/bundler-2.1.1/lib/bundler/vendor/fileutils/lib/fileutils.rb:1692: warning: previous definition of METHODS was here
bundler: failed to load command: spring (/usr/local/bundle/ruby/2.6.0/bin/spring)
ArgumentError: Trying to register Bundler::GemfileError for status code 4 but Bundler::GemfileError is already registered
  /usr/local/lib/ruby/2.6.0/bundler/errors.rb:9:in `status_code'
  /usr/local/lib/ruby/2.6.0/bundler/errors.rb:20:in `<class:GemfileError>'
  /usr/local/lib/ruby/2.6.0/bundler/errors.rb:20:in `<module:Bundler>'
  /usr/local/lib/ruby/2.6.0/bundler/errors.rb:3:in `<top (required)>'
  /usr/local/lib/ruby/2.6.0/bundler.rb:10:in `require'
  /usr/local/lib/ruby/2.6.0/bundler.rb:10:in `<top (required)>'
  /usr/local/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/run.rb:3:in `require'
  /usr/local/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/run.rb:3:in `<top (required)>'
  /usr/local/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client.rb:5:in `require'
  /usr/local/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client.rb:5:in `<top (required)>'
  /usr/local/bundle/ruby/2.6.0/gems/spring-2.1.0/bin/spring:48:in `require'
  /usr/local/bundle/ruby/2.6.0/gems/spring-2.1.0/bin/spring:48:in `<top (required)>'
  /usr/local/bundle/ruby/2.6.0/bin/spring:23:in `load'
  /usr/local/bundle/ruby/2.6.0/bin/spring:23:in `<top (required)>'
       rails  webpacker:install
Yarn not installed. Please download and install Yarn from
The command '/bin/sh -c rails new app' returned a non-zero code: 1

I tried installing yarn by adding the following 2 lines to the top of both Dockerfiles but it still won’t work, it has the same error.

FROM node:6.7.0
RUN npm install -g yarn

Source: StackOverflow