12

In the step 4/6 is showing up an error when I try to create this image in Docker:

FROM node:latest

RUN mkdir -p /app/src

WORKDIR /app/src

COPY package.json .

RUN npm install
#IT WILL COPY THE ENTIRE DIR FORECAST TO /app/src INSIDE DOCKER
COPY . .

EXPOSE 3000

CMD {"npm",  "start"}

the error that shows is:

=> ERROR [4/6] COPY package.json .                                                                                0.0s
------
 > [4/6] COPY package.json .:
------
failed to compute cache key: "/package.json" not found: not found
Azzabi Haythem
  • 2,318
  • 7
  • 26
  • 32
Lucas Batista
  • 143
  • 1
  • 5
  • 3
    On your host system, is `package.json` in the same directory as the `Dockerfile`, and are you also running `docker build .` from that same directory? – David Maze Dec 14 '20 at 01:53
  • Have you tried any of these solutions: https://stackoverflow.com/questions/64221861/failed-to-resolve-with-frontend-dockerfile-v0 . Seems like the build statement or Dockerfile capitalization can contribute, which seems odd – mikey Dec 14 '20 at 03:52

4 Answers4

12

I was getting a similar error.

failed to compute cache key: "/package.json" not found: not found

For me I included a .dockerignore file and placed many other entries other than node_modules

**/node_modules
README.md
package.json
package-lock.json
docker-compose.dev.yml

So naturally, its not copying required package.json file, and hence the error. Silly mistake from my side, hope this helps someone.

VivekDev
  • 20,868
  • 27
  • 132
  • 202
11

You can try:

COPY ["package*.json","./"]
Evgeni Lilov
  • 121
  • 1
  • 4
4

check the path of package.json, note the package.json relative to the dockerfile's path

www
  • 41
  • 1
4

I got the same error when i set Dockerfile and package.json in the same file, for me it was solved by adding "**/" to the path of the json file like this

    FROM node:14.17.3-alpine AS build
    WORKDIR /usr/src/app
    COPY **/package.json **/package-lock.json ./
    ...
Azzabi Haythem
  • 2,318
  • 7
  • 26
  • 32