webpack-dev-server 不会在 Docker Compose 中 运行

webpack-dev-server won't run in Docker Compose

当运行 docker-compose up时,我得到以下错误:

webpacker_1 | yarn run v1.22.5 webpacker_1 | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. webpacker_1 | error Command "webpack" not found. neilsite_webpacker_1 exited with code 1

我的 Dockerfile 是:

FROM ruby:2.6.5

RUN apt-get update && apt-get install -y build-essential libpq-dev

RUN curl -sL https://deb.nodesource.com/setup_14.x | bash \
&& apt-get update && apt-get install -y nodejs && rm -rf /var/lib/apt/lists/* \
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
&& apt-get update && apt-get install -y yarn && rm -rf /var/lib/apt/lists/*

ENV RAILS_ROOT /app
ENV PORT 3000

RUN mkdir $RAILS_ROOT
WORKDIR $RAILS_ROOT

COPY Gemfile $RAILS_ROOT
COPY Gemfile.lock $RAILS_ROOT
RUN bundle config --global frozen 1
RUN bundle install --without development test

COPY package.json $RAILS_ROOT
COPY yarn.lock $RAILS_ROOT
RUN yarn install --check-files --frozen-lockfile

我的 docker 撰写文件是:

version: '3.7'
services:
    app:
        build: .
        command: bash -c "rm -f /app/tmp/pids/server.pid && rails s -p 3000 -b '0.0.0.0'"
        env_file:
            - .env
        volumes:
            - .:/app
            - bundle-volume:/usr/local/bundle
            - yarn-volume:/app/node_modules
        ports:
            - '3000:3000'
        depends_on:
            - db
            - search
        environment:
            - WEBPACKER_DEV_SERVER_HOST=webpacker
    db:
        image: 'postgres:9.6'
        restart: always
        # env_file:
        #     - .env
        volumes:
            - db-volume:/var/lib/postgresql/data
        ports:
            - '5432:5432'
        environment:
            POSTGRES_PASSWORD: example
    search:
        image: 'elasticsearch:6.8.17'
        restart: always
        env_file:
            - .env
        volumes:
            - search-volume:/usr/share/elasticsearch/data
        ports:
            - '9200:9200'
    webpacker:
        build: .
        environment:
            - NODE_ENV=development
            - RAILS_ENV=development
            - WEBPACKER_DEV_SERVER_HOST=0.0.0.0
        command: ./bin/webpack-dev-server
        volumes:
            - .:/app
        ports:
            - '127.0.0.1:3035:3035'
volumes:
    bundle-volume:
    yarn-volume:
    db-volume:
    search-volume:

为什么找不到 webpack

我设法解决了这个问题。

问题是我没有在我的 webpacker 服务上为 bundle 和 yarn 配置相同的卷,因为我在我的网络服务上。