Home > Software design >  Docker build doesn't delete intermediate image even with '--rm' flag
Docker build doesn't delete intermediate image even with '--rm' flag

Time:08-30

I am trying to build react app in docker, here is my Dockerfile:

FROM node as build-step
LABEL stage=build-step
RUN mkdir /app
WORKDIR /app
COPY package.json /app
RUN npm install

COPY . /app
RUN npm run build
FROM nginx
COPY --from=build-step /app/build /usr/share/nginx/html

Using this command:

docker build . --rm  -t react-server-manual:0.1

This works, but it is creating a few other images that's useless, how do I delete them?

enter image description here

What am I missing?

CodePudding user response:

Unfortunately this --rm doesn't remove such intermediate images

You can run

docker build . -t react-server-manual:0.1 && \
docker image prune -f --filter label=stage=build-step

(or prune as separate command)

  • Related