How to Remove Docker Containers

How to Remove Docker Containers
In this article, I am going to show you how to remove Docker containers. So, let’s get started.

Requirements:

I assume you have Docker installed on your computer. If you don’t have Docker installed on your computer yet, you may check the following articles on installing Docker to install Docker on your desired Linux distribution.

If you still have any problem installing Docker, you may contact me through https://support.linuxhint.com. I will be more than happy to help.

Removing Docker Containers using CONTAINER ID:

In this section, I am going to show you how to remove a Docker container using the CONTAINER ID.

First, list all the running Docker containers with the following command:

$ docker container list

NOTE: To list containers that are not running as well, use the -a option.

$ docker container list -a

As you can see, the CONTAINER ID of all the running containers are listed.

Now, let’s say, you want to remove the container with the CONTAINER ID 3f8f57988cda.

As the container is running, you have to stop it first. To do that, run the following command:

$ docker container stop 3f8f57988cda

Now, remove the container 3f8f57988cda with the following command:

$ docker container rm 3f8f57988cda

The container 3f8f57988cda should be removed.

Removing Docker Containers using Container Names:

You can also remove a Docker container using the container name.

First, list all the running containers with the following command:

$ docker container list

The container NAMES of all the running containers should be listed.

Let’s say, you want to remove the container with the name www1. As the container is running, you must stop it before you remove it.

To stop the container www1, run the following command:

$ docker container stop www1

Now, remove the container www1 with the following command:

$ docker container rm www1

The container www1 should be removed.

Force Remove Containers:

As you saw earlier, if you want to remove a container, you have to stop the container first if it’s running. Then you can remove it.

If you want to remove a container whether it’s running or not, you have to force remove that container.

To force remove a container, let’s say www2, run the following command:

$ docker container rm -f www2

You can also use the container ID instead of container name in the above example.

Removing Multiple Containers with a Single Command:

You can also remove multiple containers at the same time.

For example, let’s say, you want to remove the container www1 and www2 at the same time. To do that, run the following command:

$ docker container rm -f  www1 www2

You can use the container ID of the containers www1 and www2 in the above example as well.

So, that’s how you remove Docker containers. Thanks for reading this article.

Related Posts
Leave a Reply

Your email address will not be published.Required fields are marked *