title: Rails on Docker won't start - execjs does not find JavaScript runtime (node)
body: <p>I am building a docker version of my rails 6.1.3.1 app.
  The original app runs fine on Ubuntu 20.04.2 with Node and I took the setup roughly from there.</p>
  <p>In Docker, Node installs fine via NVM but unfortunately Rails does not find it at startup. It seems that the Execjs gem somehow does not recognize it. A look at its sourcecode did not help, though</p>
  <p>The version and path checks during Docker creation run as supposed and without errors.</p>
  <p>Thanks a lot :)</p>
  <p>Here you go with the error message:</p>
  <pre><code>/usr/local/bundle/gems/execjs-2.7.0/lib/execjs/runtimes.rb:58:in `autodetect': Could not find a JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
      from /usr/local/bundle/gems/execjs-2.7.0/lib/execjs.rb:5:in `&lt;module:ExecJS&gt;'
      from /usr/local/bundle/gems/execjs-2.7.0/lib/execjs.rb:4:in `&lt;main&gt;'
      from /usr/local/bundle/gems/bootsnap-1.7.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
  
  ... etc. ...
  
      from /usr/local/bundle/gems/spring-2.1.1/lib/spring/application.rb:139:in `run'
      from /usr/local/bundle/gems/spring-2.1.1/lib/spring/application/boot.rb:19:in `&lt;top (required)&gt;'
      from /usr/local/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
      from /usr/local/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
  </code></pre>
  <p>The dockerfile:</p>
  <pre><code># Dockerfile
  # Use ruby image to build our own image
  FROM ruby:2.6.6
  # We specify everything will happen within the /app folder inside the container
  WORKDIR /app
  # We copy these files from our current application to the /app container
  COPY Gemfile Gemfile.lock ./
  
  # install Node with NVM
  # was a pain to make nvm run after install then followed https://stackoverflow.com/a/60137919/10297304
  SHELL [&quot;/bin/bash&quot;, &quot;--login&quot;, &quot;-i&quot;, &quot;-c&quot;] # different way of execution sources .bashrc..
  RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.0/install.sh | bash
  SHELL [&quot;/bin/bash&quot;, &quot;--login&quot;, &quot;-c&quot;] # back to normal
  RUN nvm install 14.15.0
  RUN nvm alias default v14.15.0
  RUN npm install --global yarn
  RUN gem install bundler:2.2.11 # otherwise version mismatch
  RUN bundle install
  RUN yarn install
  RUN which node
  RUN node -v
  RUN nvm -v
  RUN yarn -v
  # We copy all the files from our current application to the /app container
  COPY . .
  # We expose the port
  EXPOSE 3000
  # Start the main process.
  CMD [&quot;rails&quot;, &quot;server&quot;, &quot;-b&quot;, &quot;0.0.0.0&quot;]
  </code></pre>