我有一个gatsby
docker镜像,使用docker run
运行时可以按预期工作,但是当我使用docker-compose up
运行它时,出现以下错误:
There was a problem loading the local develop command. Gatsby may not be installed in your site's "node_modules" directory. Perhaps you need to run "npm install"? You might need to delete your "package-lock.json" as well.
我的
Dockerfile
看起来像这样:FROM node:12-buster
RUN npm install --global gatsby-cli && gatsby telemetry --disable
WORKDIR /app
COPY package*.json /app/
RUN npm install --force
COPY . .
EXPOSE 8000
CMD ["npm", "run", "develop"]
撰写文件如下所示:
frontend:
build: frontend
image: frontend
volumes:
- ./frontend:/app
ports:
- "8000:8000"
depends_on:
- backend
最佳答案
当代码在build上下文中时,该镜像将正常工作,因为所有RUN命令都将在docker build镜像过程中执行。
当您像在docker-compose上一样实例化镜像时,您未在运行:
RUN npm install --force
因为它是在构建镜像期间执行的。在发射容器期间没有。
因此,要解决您的问题并考虑如何构建镜像,则无需包括卷,而应将代码作为构建上下文。
version: "3.7"
services:
webapp:
build:
context: ./dir
dockerfile: Dockerfile
https://docs.docker.com/compose/compose-file/
关于node.js - Docker镜像与docker run配合使用,但不适用于docker-compose up,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60465367/