0

I am currently learning docker and I noticed new thing for me in some Dockerfile. I actually do not understand what is the point of this line in the dockerfile: FROM nginx COPY --from=builder /usr/src/frontend/my-frontend/build /usr/share/nginx/html Can someone please explain me what it does?

Whole dockerfile:

FROM node:14-alpine AS builder
WORKDIR /usr/src/frontend/my-frontend
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
RUN npm run build
FROM nginx 
COPY --from=builder /usr/src/frontend/my-frontend/build /usr/share/nginx/html

And what is the diffrence between normal FROM node... and FROM node... AS builder?

randomobject123
  • 113
  • 1
  • 2
  • 7
  • Both syntaxes are part of Docker multi-stage builds, and [the currently-accepted answer to the linked question](https://stackoverflow.com/a/33322374) explains both `FROM ... AS` and `COPY --from=...`. – David Maze May 20 '22 at 00:41

1 Answers1

0

you should read about Docker multistage builds.

Each FROM clause introduces a new stage. The last FROM is the stage from which your result image will be built. All other stages are auxiliary and their purpose is to support (with build artifacts) the final stage.

In your example, the 1st stage just builds the Javascript application. Then it passes it (COPY) to your final stage.

Michail Alexakis
  • 1,405
  • 15
  • 14