Erfan Taghvaei
Erfan Taghvaei

Reputation: 162

Docker can't find index.html when dockerizing react app

I am pretty new to Docker and I want to dockerize my react app, the index.html file is under my public folder in the react project. When I run the docker image, it fails and gives me an error stating that the index.html file is missing.

The error:

[email protected] start react-scripts start

Could not find a required file. Name: index.html Searched in: /app/public npm notice npm notice New minor version of npm available! 8.11.0 -> 8.19.2 npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.19.2 npm notice Run npm install -g [email protected] to update! npm notice

Below is the code of my Dockerfile:

FROM node:lts-alpine3.14 as build

RUN apk update && \
  apk upgrade && \
  apk add --no-cache bash git openssh

RUN mkdir /app

WORKDIR /app

COPY package.json .

RUN npm install -g --force npm@latest typescript@latest yarn@latest

RUN npm install

COPY . ./

RUN  npm run build

# ---------------

FROM node:lts-alpine3.14

RUN mkdir -p /app/build

RUN apk update && \
  apk upgrade && \
  apk add git

WORKDIR /app

COPY --from=build /app/package.json .

RUN yarn install --production


COPY --from=build . .

EXPOSE 3000
EXPOSE 3001

ENV SERVER_PORT=3000
ENV API_PORT=3001
ENV NODE_ENV production

CMD ["npm", "start"]


Upvotes: 0

Views: 824

Answers (1)

Đorđe Radujković
Đorđe Radujković

Reputation: 21

Try to attach the shell to the container with

docker exec -it CONTAINER_NAME bash

and see where is index.html file and where you need to copy it

Upvotes: 1

Related Questions