![](/img/trans.png)
[英]Is copying /node_modules inside a Docker image not a good idea?
[英]Docker Node image not recognizing node_modules folder when it's available in image
我有一个 Next.js 应用程序,我想使用 Docker compose
我的docker.compose.yml
:
version: "3.6"
services:
...
next:
container_name: next
build:
context: ./frontend/next
dockerfile: Dockerfile.development
restart: always
ports:
- 3000:3000
volumes:
- ./frontend/next:/frontend-app
- ./frontend/next/package.json:/frontend-app/package.json
- ./frontend/next/yarn.lock:/frontend-app/yarn.lock
我的./frontend/next/Dockerfile.development
是:
FROM mhart/alpine-node
RUN mkdir /frontend-app
WORKDIR /frontend-app
COPY package.json yarn.lock ./
RUN yarn install
COPY . .
EXPOSE 3000
CMD ["yarn", "dev"]
当我运行docker-compose build
然后docker-compose up
我得到这个错误:
next | yarn run v1.22.10
next | $ next dev
next | /bin/sh: next: not found
next | error Command failed with exit code 127.
next | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
运行docker-compose build
时,它显示 yarn install 运行正常。 即使我在我的图像中运行 shell 并执行ls /frontend-app
我得到node_modules
存在。
我在这里做错了什么?
编辑:我的./frontend/next/.dockerignore
是
.next/
node_modules/
Dockerfile
您没有将 node_modules 发送到 docker,这意味着它找不到下一个 bin。 从 .dockerignore 中删除 node_modules 和 .next
所以在将所有文件复制到容器中之后,我删除了“package-lock.json”。
这是我的 Dockerfile
./project
Dockerfile
docker-compose.yml
这是我的 docker-compose 文件
version: "3" services: web: build: . ports: - "3000:3000" volumes: -./project:/app command: > sh -c "npm i && npm run dev"
有用。
*注意:“./project”是源文件夹
树文件夹: ./project Dockerfile docker-compose.yml
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.