Dockerfile copy from build failing for create-react-app

Published

I have a react app I’m trying to dockerize for production. It was based off create-react-app. To run the app locally, I am in the app’s root folder and I run npm start. This works. I built the app with npm run build. Then I try to create the docker image with docker build . -t app-name. This is failing for not being able to find the folder I’m trying to copy the built app from (I think).

Here’s what’s in my Dockerfile:

FROM node:13.12.0-alpine as build
WORKDIR /src
ENV PATH /node_modules/.bin:$PATH
COPY package.json ./
COPY package-lock.json ./
RUN npm install --silent
COPY . ./

RUN npm run build

FROM nginx:alpine
COPY --from=build build /usr/share/nginx/html
EXPOSE 80

CMD ["npm", "start"]

I’m pretty sure I’ve got something wrong on the COPY --from line.

The app structure is like this, if it matters

-app-name (folder)
  -src (folder)
  -build (folder)
  -dockerfile
  -other stuff, but I think I listed what matters

The error I get is failed to compute cache key: "/build" not found: not found

I’m running my commands in windows powershell.

What do I need to change?

Source: Docker Questions

Published
Categorised as create-react-app, docker, dockerfile Tagged , ,

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq