Dawn17
Dawn17

Reputation: 8297

Running a React Dockerfile gives me an error

FROM node:latest

WORKDIR /frontend/

ENV PATH /frontend/node_modules/.bin:$PATH

COPY package.json /frontend/package.json
RUN npm install --silent
RUN npm install [email protected] -g --silent

CMD ["npm", "run", "start"]

This is how I built by Dockerfile for my React frontend. I used docker build -t frontend:dev . to build it and docker run -p 3001:3000 --rm frontend:dev to run it.

However, this gives me,

[email protected] start /frontend react-scripts start

Could not find a required file.
  Name: index.html
  Searched in: /frontend/public
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `react-scripts start`ts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Although I can find index.html in public.

Any help?

Upvotes: 0

Views: 222

Answers (1)

Adiii
Adiii

Reputation: 59966

Seems like you you did not copy the code in your Dockerfile, as no copy directive execpt package.json?

Add this in your Dockerfile

COPY . /frontend/

Upvotes: 1

Related Questions