How to stop all the docker containers? How to destroy docker containers quickly? How to remove all the downloaded docker images? Very often we deploy the containers for testing and spend time cleaning up the containers one by one. This article will provide quick commands to stop all the running containers and delete them quickly.
Stop all the running containers
1.Login to the server and list the running containers.
[root@BIVM ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 64bb68c69c55 incubator-superset_superset "/usr/bin/docker-ent…" 3 weeks ago Up 14 minutes (healthy) 8080/tcp, 0.0.0.0:8088->8088/tcp incubator-superset_superset_1 66635660578a incubator-superset_superset-worker "/usr/bin/docker-ent…" 3 weeks ago Up 14 minutes (unhealthy) 8080/tcp incubator-superset_superset-worker_1 c9c8bdb36e1d postgres:10 "docker-entrypoint.s…" 3 weeks ago Up 14 minutes 127.0.0.1:5432->5432/tcp incubator-superset_db_1 5e01726d5bf1 redis:3.2 "docker-entrypoint.s…" 3 weeks ago Up 14 minutes 127.0.0.1:6379->6379/tcp incubator-superset_redis_1 [root@BIVM ~]#
2. Stop all the running docker containers.
[root@BIVM ~]# docker stop $(docker ps -a -q) 64bb68c69c55 66635660578a d0d018382609 1fe98f4ad2f8 c9c8bdb36e1d 5e01726d5bf1 [root@BIVM ~]# [root@BIVM ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES [root@BIVM ~]#
Remove all the stopped containers
1. Remove all the stopped docker containers
[root@BIVM ~]# docker rm $(docker ps -a -q)
64bb68c69c55
66635660578a
d0d018382609
1fe98f4ad2f8
c9c8bdb36e1d
5e01726d5bf1
[root@BIVM ~]#
Delete all the docker images
1. All the docker images can be deleted using single command.
[root@BIVM ~]# docker rmi $(docker images -q)
Deleted: sha256:02ddb9aaa04c7c2fac1bb6448c03fa9620909611f6cfe7a55a035b36e697cf83
Deleted: sha256:89a57a73e3bbd3189cdcfac29d15a26dba13ff930ccee3220f61001409d34284
Deleted: sha256:acb1b51ac6cd058a9d466e4e0bff4c3c1a7dd491d3af969e92f899b708dc78d3
Deleted: sha256:64ac48a17a77e31a60559fd4056a365e793f1016e6a92ff061f78a6600c4e46b
Deleted: sha256:0a48cdeaf73beb0f68aa197a0bfa184429465fc79daa5a1b563646bdcb61b913
Deleted: sha256:bca4d2c970811de6dd72536085d219ec6927ad115faffbc51375d7883e87de82
Deleted: sha256:f1bfe7d625f5416388d22d55d903885a7ae190b77b0edc2bca7dc5ec9b96ac4c
Deleted: sha256:5fcb92c9e3e142b6fecc578330a7c081ef4d998ba1568cf6ebf06d670c88ec5d
Deleted: sha256:ead0d89bb788d899431d982aca904598feed9205dc6231204326371e3e7ab52f
Deleted: sha256:fe1271099bf69a143657b3abb1932486775a29d521a45150951d902b04169920
You could also force the image deletion using following command.
[root@BIVM ~]# docker rmi -f $(docker images -q)
Leave a Reply