【发布时间】:2021-05-17 02:37:59
【问题描述】:
我正在使用 Yarn 运行带有 Webpacker 的 Ruby on Rails 应用程序,并尝试通过 Docker Compose 在 Docker 上运行它。当我运行docker compose build 时,它看起来运行成功,但是找不到 node_modules 文件夹,我无法使用任何节点包。我尝试按照其他帖子中的建议将- /app/node_modules 添加到卷中,但无济于事。
FROM ruby:3.0.0
RUN bundle config --global frozen 1
WORKDIR /app
COPY Gemfile Gemfile.lock ./
RUN bundle install
COPY . .
RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash -
RUN apt-get install -y nodejs
RUN npm install --global yarn
RUN yarn install
docker-compose.yml
version: "3.9"
services:
web:
build: .
ports:
- "3000:3000"
command: "rails server -b 0.0.0.0"
volumes:
- ./:/app
- /app/node_modules
db:
image: "postgres:13"
ports:
- "5432:5432"
volumes:
- ./pgdata:/var/lib/postgresql/data
environment:
- POSTGRES_USER=user
- POSTGRES_PASSWORD=password
【问题讨论】:
-
你试过
docker-compose up,看看日志说了什么? -
在
/app上安装卷隐藏了 Dockerfile 所做的一切。删除web服务的整个volumes:部分。 -
另一个奇怪的事情是在我运行图像之后,我可以运行 docker compose exec web yarn install 然后它实际上确实添加了节点模块,但我需要它在构建步骤中运行
标签: node.js ruby-on-rails docker yarnpkg