How to Remove Docker Containers

29/12/2020
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.

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

How to Stop All Docker Containers

In this article, I am going to show you how to stop all Docker containers on your Docker host. So, let’s get started. Requirements: You...
29/12/2020

Docker Overlay Driver and Overlay Networking

Docker comes with three networking drivers by default. Network adapters are also initialized using these drivers, carrying...
29/12/2020

Docker basic Command Line Tips and Tricks

Docker is an Open Source project for developers and system administrators to build, ship, and run distributed applications...
29/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

Dịch vụ thuê mua proxy US UK uy tín, chất lượng số #1
13/05/2024

Thuê mua proxy Việt Nam: Báo giá & các thông tin MỚI NHẤT
13/05/2024

Dịch vụ thuê mua proxy giá rẻ an toàn, tốc độ cao
13/05/2024

Thuê mua proxy V6 uy tín, chất lượng tại đâu?
11/05/2024

Thuê mua proxy Tiktok tăng doanh thu, hiệu quả cao
11/05/2024