Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 309
Émile Pettersen-Coulombe Avatar asked Aug 12 '18 17:08

Émile Pettersen-Coulombe


2 Answers

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.

like image 118
norbjd Avatar answered Oct 01 '22 22:10

norbjd


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...

like image 31
Scott Williams Avatar answered Oct 01 '22 22:10

Scott Williams