My Dockerfile contains this:

### STAGE 1: Build Angular app ###
FROM node:14.15 AS build
WORKDIR /usr/src/app
COPY src/hub/package.json ./
RUN npm cache verify
RUN npm install
COPY src/hub/ .
RUN npm run-script build-azdev
RUN npm prune --production

### STAGE 2: Run Angular app in nginx ###
FROM nginx:1.19-alpine
COPY /scripts/nginx/nginx.conf /etc/nginx/nginx.conf
RUN rm -rf /usr/share/nginx/html/*
COPY --from=build /usr/src/app/dist/* /usr/share/nginx/html/
CMD ["nginx", "-g", "daemon off;"]

Once COPY --from=build /usr/src/app/dist/* /usr/share/nginx/html/ is done, should the contents of WORKDIR (/usr/src/app) be deleted once Stage 2 is done building?

  • Deleted from where? Show the command and output that has unexpected output for you. – BMitch Dec 10 '20 at 16:41

When creating an image using a Dockerfile, docker layers are created for each step. The description of layers can be found on the official docker page.

Accordingly, when using Multistage to create an image, it introduces a new build step that can be named using an alias in the FROM statement, and all layers except the image layer created via the last FROM statement are deleted.

After build your image, check if the layer that contains WORKDIR whether exists or not using docker image inspect. I think you probably know the unique layer value for each step.

You can see the image consists with which layers. e.g.,

$docker image inspect [OPTIONS] 464503b73bfe # IMAGE
        "Id": "sha256:464bf1...46c",

        "RootFS": {
            "Type": "layers",
            "Layers": [

Not the answer you're looking for? Browse other questions tagged or ask your own question.