【问题标题】:Rails on Docker won't start - execjs does not find JavaScript runtime (node)Docker 上的 Rails 无法启动 - execjs 找不到 JavaScript 运行时(节点)
【发布时间】:2021-08-02 02:42:19
【问题描述】:

我正在构建我的 rails 6.1.3.1 应用程序的 docker 版本。 原始应用程序在带有 Node 的 Ubuntu 20.04.2 上运行良好,我大致从那里进行了设置。

在 Docker 中,Node 可以通过 NVM 正常安装,但不幸的是 Rails 在启动时找不到它。似乎 Execjs gem 不知何故无法识别它。不过看看它的源代码并没有帮助

在 Docker 创建期间的版本和路径检查按预期运行且没有错误。

非常感谢:)

这里有错误信息:

/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 `<module:ExecJS>'
    from /usr/local/bundle/gems/execjs-2.7.0/lib/execjs.rb:4:in `<main>'
    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 `<top (required)>'
    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'

码头文件:

# 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 ["/bin/bash", "--login", "-i", "-c"] # different way of execution sources .bashrc..
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.0/install.sh | bash
SHELL ["/bin/bash", "--login", "-c"] # 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 ["rails", "server", "-b", "0.0.0.0"]

【问题讨论】:

  • nvm 是否也安装节点?为什么不添加单独的 RUN 指令来安装 node 和 nvm?
  • RUN nvm install 14.15.0 安装节点 .. 我在这里使用已知的工作 Ubuntu 设置。但我认为即使只使用单个版本的节点,它也是使用 nvm 的推荐方式

标签: node.js ruby-on-rails bash docker execjs


【解决方案1】:

我遇到了同样的问题。 将 Docker 引擎从 18 升级到 20 后就解决了

【讨论】:

    猜你喜欢
    • 2014-12-10
    • 2013-10-25
    • 2011-09-11
    • 2012-03-01
    • 1970-01-01
    • 2011-12-24
    • 2019-11-19
    • 2012-12-20
    相关资源
    最近更新 更多