Samar Pratap Singh
Samar Pratap Singh

Reputation: 531

package.json not found in node:13-alpine docker container

I made 2 docker images from 2 folder in this repo. The dockerfile was:

FROM node:13-alpine
EXPOSE 5000
RUN mkdir /app
RUN mkdir -p /home/app
COPY . /home/app
RUN npm install
CMD ["npm","run","start"]

But the docker logs showed that the package.json file was not found and hence the containers closed, I can't even enter the terminal of the containers to see the available files.

The error output is in the below image.

enter image description here

To reproduce the error, clone the repo and run sudo docker-compose -f docker-compose.yaml up

Upvotes: 0

Views: 584

Answers (1)

ikhvjs
ikhvjs

Reputation: 5937

You didn't specify the working directory in your dockerfile and that's why the package.json cannot be found.

Ref: https://docs.docker.com/engine/reference/builder/#workdir

add WORKDIR before RUN npm install

WORKDIR /home/app
RUN npm install

Upvotes: 1

Related Questions