Removing containers
When we run the docker container ls -a
command, we can see quite a few containers that are in the Exited
status. If we don’t need these containers anymore, then it is a good thing to remove them from memory; otherwise, they unnecessarily occupy precious resources. The command to remove a container is as follows:
$ docker container rm <container ID>
Here, <container ID>
stands for the ID of the container – a SHA-256 code – that we want to remove. Another way to remove a container is the following:
$ docker container rm <container name>
Here, we use the name of the container.
Challenge
Try to remove one of your exited containers using its ID.
Sometimes, removing a container will not work as it is still running. If we want to force a removal, no matter what the condition of the container currently is, we can use the -f
or --force
command-line parameter:
$ docker container rm <container ID> --force...