Ruby on Rails 6 + Docker = Webpacker::Manifest::MissingEntryError?

Posted

技术标签:

【中文标题】Ruby on Rails 6 + Docker = Webpacker::Manifest::MissingEntryError?【英文标题】:Ruby on Rails 6 + Docker = Webpacker::Manifest::MissingEntryError? 【发布时间】:2020-03-11 01:37:12 【问题描述】:

尝试将我的 Rails 应用程序作为 Docker 容器运行,但打开页面时出现以下错误:

Webpacker can't find application in /app/public/packs/manifest.json. Possible causes:
1. You want to set webpacker.yml value of compile to true for your environment
   unless you are using the `webpack -w` or the webpack-dev-server.
2. webpack has not yet re-run to reflect updates.
3. You have misconfigured Webpacker's config/webpacker.yml file.
4. Your webpack configuration is not creating a manifest.
Your manifest contains:


当我使用 rails s 运行应用程序时,它运行良好,并且创建了 public/packs 文件夹。 在日志中也有

/usr/local/bundle/gems/webpacker-4.2.0/lib/webpacker/runner.rb:13:in ``': No such file or directory - yarn (Errno::ENOENT)

错误,虽然我检查了容器 yarn -v 显示安装了 yarn。

Dockerfile

FROM ruby:2.6.3
RUN apt-get update -qq \
    && curl -sL https://deb.nodesource.com/setup_12.x  | bash - \
    && apt-get install -y nodejs \
    && curl -o- -L https://yarnpkg.com/install.sh | bash
RUN mkdir /app
WORKDIR /app
COPY Gemfile /app/Gemfile
COPY Gemfile.lock /app/Gemfile.lock
RUN bundle install
COPY . /app

# Add a script to be executed every time the container starts.
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000

# Start the main process.
CMD ["rails", "server", "-b", "0.0.0.0"]

docker-compose.yml

version: '3'
services:
  webpacker:
    build: .
    env_file:
      - '.env.docker'
    command: ./bin/webpack-dev-server
    volumes:
      - .:/app
    ports:
      - '3035:3035'
  web:
    build: .
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    volumes:
      - .:/app
    ports:
      - "3000:3000"

.env.docker

NODE_ENV=development
RAILS_ENV=development
WEBPACKER_DEV_SERVER_HOST=0.0.0.0

【问题讨论】:

更新:我可以使用 docker exec -it sitemap_web_1 bash -lc "./bin/webpack-dev-server" 手动通过登录 shell 启动 webpack-dev-server。看起来问题的根源在于环境可见性 你有没有想过这个问题?现在使用 Rails 6.0.3 和 19.03.8 处理这个问题 【参考方案1】:

按照以下步骤操作。

i) docker-compose run #rails_app_name yarn

然后再次构建您的项目

ii) docker-compose build #rails_app_name

iii) docker-compose up

参考: [1]:https://github.com/rails/webpacker/issues/1568

【讨论】:

以上是关于Ruby on Rails 6 + Docker = Webpacker::Manifest::MissingEntryError?的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 docker(ruby on rails)设置 anycable?

尝试从 Ruby on Rails 连接到 postgres(在 docker 容器中)

使用Ruby on Rails开启Docker微服务之旅

通过Ruby on Rails和docker构建微服务架构之入门教程

让 Ruby-on-Rails 6/Webpack + Bootstrap 一起正常工作的问题

Ruby on Rails - 在 OSX 上使用 Ruby 2.4.4 而不是 rails 5.1.6 的配置问题/异常