我正在尝试在 docker 中运行 Node 镜像,但出现此错误:
npm WARN saveError ENOENT: no such file or directory, open '/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/package.json'
npm WARN !invalid#2 No description
npm WARN !invalid#2 No repository field.
npm WARN !invalid#2 No README data
npm WARN !invalid#2 No license field.
这是我的 docker 文件。我想把我所有的项目文件放在容器的/home/app/文件夹中:
# Use an official node runtime as a parent image
FROM node:10
# Set the working directory to /home/app
#WORKDIR /home/app/
# Bundle app source
COPY . /home/app/
# If you are building your code for production
# RUN npm install --only=production
RUN npm install
# Make port 8000 available to the world outside this container
EXPOSE 8000
CMD npm run dev
我在 Windows 上,我使用 hyper-V。我的 package.json 与我的 Dockerfile 处于同一级别。
有任何想法吗?
谢谢
最佳答案
当npm install
命令运行,工作目录可能是/
,并且没有 package.json
这里。
只需取消注释您的行 WORKDIR /home/app/
在您的 Dockerfile
.