Docker error: no such file or directory, open '/package.json'

隐身守侯 提交于 2021-02-07 06:08:54

问题


I'm trying to run a node image inside docker but I have this error:

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.

Here is my docker file. I want to put all my project files in /home/app/ folder in the container:

# 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

I'm on windows and I use hyper-V. My package.json is at the same level as my Dockerfile.

Any ideas?

Thanks


回答1:


When npm install command is run, the working directory is probably /, and there is no package.json here.

Just uncomment your line WORKDIR /home/app/ in your Dockerfile.




回答2:


My silly mistake was that I had forgotten to specify my WORKDIR before attempting to run my npm commands... Hope this helps someone too! Be sure to make sure your WORKDIR is accurate for the CMD line...



来源:https://stackoverflow.com/questions/51811326/docker-error-no-such-file-or-directory-open-package-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!