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.
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.
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).
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).
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With