Docker错误:没有这样的文件或目录,请打开'/package.json'

时间:2018-08-12 17:41:38

标签: node.js docker package.json

我正在尝试在docker内部运行节点映像,但出现此错误:

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处于同一级别。

有什么想法吗?

谢谢

2 个答案:

答案 0 :(得分:3)

运行npm install命令时,工作目录可能是/,这里没有package.json

只需在WORKDIR /home/app/中取消注释行Dockerfile

答案 1 :(得分:0)

我的愚蠢错误是,我在尝试运行npm命令之前忘记指定WORKDIR了……希望这对别人也有帮助! 请确保您的WORKDIRCMD行中是正确的...