Removing the containers

To remove the container from the host, we use the docker rm command. The syntax is as follows:

$ docker rm [OPTIONS] CONTAINER [CONTAINER...]  

You can specify a single container or more containers at once. If you are running short-term foreground processes over and over many times, these file systems can grow rapidly in size. There's a solution for that: instead of cleaning manually by hand, tell Docker to automatically clean up the container and remove the file system when the container exits. You do this by adding the --rm flag, so that the container data is removed automatically after the process has finished.

--rm flag will make Docker remove container after it has been shut down.

For example, use the run command ...

Get Docker and Kubernetes for Java Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.