skip to Main Content

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


  1. 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 them

    FROM node AS prod # node-prod
    ...
    FROM nginx:alpine AS prod # nginx-prod
    

    See more at here

    Login or Signup to reply.
  2. You have the same stage name for both the stages as this causes the circular dependency error.

    Change one of them

    FROM nginx:alpine AS prod
    

    into

    FROM nginx:alpine AS nginx-prod
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search