问题
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