Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No package.json on docker

Tags:

docker

reactjs

I am creating a docker image of a react-app and it return me an error that:

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

Notice created a lockfile as package-lock.json. You should commit this file.

Here the Dockerfile

FROM node:alpine
RUN npm install
RUN npm run build
like image 464
lfermincas Avatar asked Jun 13 '26 08:06

lfermincas


1 Answers

In your Docker file you need to specify the COPY execution to send to the container before execute copy the package.json, modified your Docker file to be like this:

FROM node:alpine
COPY package.json .
RUN npm install --no-package-lock
COPY . .
RUN npm run build

COPY package.json .

This command is to copy your package.json to the new container

RUN npm install --no-package-lock

This one is to install all of the dependencies of your project on the new container

COPY . .

This on is to move all your code to the new container

like image 139
belgica Sosa Avatar answered Jun 16 '26 06:06

belgica Sosa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!