I followed this documentation to dockerize my react app and I did everything as it said, but I get this ERROR: failed to solve: circular dependency detected on stage: prod
when try to execute docker image build -t react:v1 .
this is my Dockerfile (exactly as documentation)
FROM node AS prod
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
# RUN npm test - if you want to test before to build
RUN npm run build
FROM nginx:alpine AS prod
WORKDIR /usr/share/nginx/html
COPY --from=prod /app/build .
EXPOSE 80
# run nginx with global directives and daemon off
ENTRYPOINT ["nginx", "-g", "daemon off;"]
and this is .dockerignore
/node_modules
I’m also using Ubuntu on vmware workstation.
2
Answers
If you use multi-stage builds, name’s stage must be unique in Dockerfile.
prod
was be used in 2 stages in your script, just change one of themSee more at here
You have the same stage name for both the stages as this causes the circular dependency error.
Change one of them
into