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

Set up a MongoDB server with Docker

In this article, I am going to show you how to use Docker Compose to create a MongoDB container and access it using Mongo...
29/12/2020

How to Remove All Docker Images

Docker keeps a local copy of every Docker image you download. So, your Docker host may get congested at some point. All...
29/12/2020

How to build a Nodejs app on docker

Docker has become a hot topic of conversation nowadays especially among developers. So what is docker? Docker is an opensource...
29/12/2020
Bài Viết

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

Tìm Hiểu Về Thuê Proxy US – Lợi Ích và Cách Sử Dụng Hiệu Quả
11/12/2024

Mua Proxy V6 Nuôi Facebook Spam Hiệu Quả Tại Onetcomvn
03/06/2024

Hướng dẫn cách sử dụng ProxyDroid để duyệt web ẩn danh
03/06/2024

Mua proxy Onet uy tín tại Onet.com.vn
03/06/2024

Thuê mua IPv4 giá rẻ, tốc độ nhanh, uy tín #1
28/05/2024