Removing a container
We can remove a container permanently, but before that, we have to stop the container or use the force option. In this recipe, we'll create and remove a container.
Getting ready
Ensure that the Docker daemon is running on the host and can be connected through the Docker client. You will also need some containers in a stopped or running state to delete them.
How to do it...
Use the following command:
$ docker container rm [OPTIONS] CONTAINER [CONTAINER]
Or run the following legacy command:
$ docker rm [OPTIONS] CONTAINER [CONTAINER]
Let's first create a container, and then delete it using the following commands:
$ ID=$(docker container create ubuntu /bin/bash)$ docker container stop $ID$ docker container rm $ID

As we can see from the preceding screenshot, the container did not show up, which just entered the docker container ls
command after being stopped. We had to provide the -a
option in order to list it.
There's more...
To remove a running container, it must be stopped first...