How to remove a docker container

Posted on

This article contains information on how to remove a docker container using a command line. Docker itself according to the definition in this link, is a technology for creating, deploying, and running applications by using containers in an easier way. Furthermore, those containers allow developers to package up an application with all of the parts it needs, such as libraries and other dependencies, and ship it all out as one package.

So, the following is a command execution for displaying all available containers whether it is currently running or not :

docker ps -a

The following is the execution of the above command in a real situation for an example :

root@hostname:~# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS               NAMES
0b4fc76de6c2        app                 "php index.php"          40 minutes ago      Exited (0) 40 minutes ago                       test
cd9384edb3d3        app                 "php index.php"          5 hours ago         Exited (0) 5 hours ago                          app
cba1ecabe609        hello-world         "/hello"                 3 months ago        Exited (0) 3 months ago                         helloworld_my-test_1
root@hostname:~#

In this article, the target for the removal process is the container with the id of ‘cd9384edb3d3’. So, in order to remove the container, just execute the following command in the command line :

docker container rm [container_id]

The above command execution to remove the specific container by selecting the correct container id. Finally, using the above command pattern, the following is an example of using the command with the following output :

root@hostname~# docker container rm cba1ecabe609
cba1ecabe609
root@hostname:~#

Meanwhile, after successfully executing the command, try to check the list of available docker containers again by typing the following command :

root@hostname:~# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS               NAMES
0b4fc76de6c2        app                 "php index.php"          44 minutes ago      Exited (0) 44 minutes ago                       test
cd9384edb3d3        app                 "php index.php"          5 hours ago         Exited (0) 5 hours ago                          app
root@hostname:~#

At last, the container with the ontainer with the id of ‘cba1ecabe609 is no longer. It means the execution of the command is a success.

Leave a Reply