Rails 6 - 无法通过 Docker 联网 Webpack 开发服务器

Bry*_*yce 5 ruby-on-rails docker webpack

我目前使用这些相关的 gem/库启动并运行了一个 Rails 6 应用程序:

  • 'rails', '6.1.1'(红宝石)
  • 'webpacker', '5.1.1'(红宝石)
  • "@rails/webpacker": "^5.1.1"(NPM包)
  • "webpack": "^4.0.0"(NPM包)
  • "webpack-cli": "^3.2.1"(NPM包)
  • "webpack-dev-server": "^3.1.14"(NPM包)

我的webpacker.yml文件包含以下开发服务器配置:

development:
  <<: *default
  compile: true

  dev_server:
    https: false
    host: localhost
    port: 3035
    public: localhost:3035
    hmr: false
    inline: true
    overlay: true
    compress: true
    disable_host_check: true
    use_local_ip: false
    quiet: false
    headers:
      'Access-Control-Allow-Origin': '*'
    watch_options:
      ignored: /node_modules/

Run Code Online (Sandbox Code Playgroud)

当我仅在本地计算机上运行它时,其中一个终端提供 Rails 内容 ( bundle exec rails s),另一个终端提供开发服务器内容 ( bundle exec bin/webpack-dev-server),一切都会按预期进行。

然而,我一直在尝试将所有内容转移到 Docker,但无法让开发服务器与docker-compose. 这是我的(简化的)docker-compose.yml文件:

version: '3.4'

services:
  dev: &dev
    image: my_image
    depends_on:
      - webpacker
    entrypoint: ./docker/entrypoints/app-entrypoint.sh
    ports:
      - '3000:3000'
      - '80:80'
      - '22:22'
    env_file: .env
    environment:
      RAILS_ENV: development
      WEBPACKER_DEV_SERVER_HOST: webpacker
      WEBPACKER_DEV_SERVER_PORT: 3035

  webpacker: &webpacker
    image: my_image
    entrypoint: ./docker/entrypoints/webpacker-entrypoint.sh
    ports:
      - '3035:3035'
    environment:
      NODE_ENV: development
      RAILS_ENV: development
      WEBPACKER_DEV_SERVER_HOST: 0.0.0.0
Run Code Online (Sandbox Code Playgroud)

当我将其全部启动时,我可以看到 webpacker 在 处提供我的资源http://0.0.0.0:3035。但是当我导航到应用程序的主页时,出现以下错误:

Webpacker can't find application.js 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:
{
}
Run Code Online (Sandbox Code Playgroud)

这显然是所有东西如何联网的问题,但我已经尝试了我能想到的对不同配置文件的所有更改,但仍然没有成功。