Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the difference between --force-rm and --rm when running docker build command

Tags:

docker

When we build docker images using docker build command we have two options --force-rm=true and --rm=true to remove intermediate containers. what is the difference between these two options and in what scenarios should each be used.

like image 745
Vikram3891 Avatar asked Feb 03 '16 04:02

Vikram3891


People also ask

What is -- rm in docker build?

docker build has: --rm=true Remove intermediate containers after a successful build. That means that, in case of an unsuccessful build, those intermediate containers are not removed. That allows for debugging the last intermediate container, or committing it as an intermediate image.

What does the -- rm option do when used with the docker Run command?

The --rm causes Docker to automatically remove the container when it exits. The image being used to create the container is generally specified as <name>:<tag> such as ruby:latest . If the specified image is not available locally, Docker will attempt to retrieve it from Docker Hub (or any connected Docker registry).

What is the difference between the docker container prune command and the docker container rm command?

docker rm -f ... Forces the removal of a running container (uses SIGKILL) which means that it will remove running containers. docker container prune -f will remove all stopped containers without asking for confirmation (no [y/N] prompt will be printed).

What is the difference between docker build and run?

docker build builds a new image from the source code. docker create creates a writeable container from the image and prepares it for running. docker run creates the container (same as docker create ) and runs it.


1 Answers

docker build has:

--rm=true                       Remove intermediate containers after a successful build 

That means that, in case of an unsuccessful build, those intermediate containers are not removed. That allows for debugging the last intermediate container, or committing it as an intermediate image.

But with --force-rm=true, those intermediate containers would always been removed even in case of an unsuccessful compilation.

like image 200
VonC Avatar answered Oct 07 '22 19:10

VonC