docker clean up containers and images

During the operation of docker, many containers will be created unknowingly, many of which are unused and need to be cleaned up.
The following are some cleaning methods, one by one is definitely inefficient, and batch cleaning is very interesting.

View running containers

# docker ps -q
9b9f97905e36

Deactivate all running containers

# docker stop $(docker ps -q)
9b9f97905e36

delete all containers

# docker rm $(docker ps -aq)
9b9f97905e36
ce255ba7637e
f126bad55cac
c10a4c3541f5
1949036422c3
518abb0ea706
8e44bd1abf81
df01fe711d00
0931fac89930
1e16b5a972af
15c0cb22672e
241a780f8634

One command to deactivate and delete containers

root@ThinkPad:/home/jiqing# docker run -d -p 9000:80 jiqing9006/centos:httpd /bin/sh -c /usr/local/bin/start.sh
0a9d3b5e5f957cc87abc396486abd07e325f5c70f46f0149e22efb5e0a4f8a24
root@ThinkPad:/home/jiqing# docker ps -aq
0a9d3b5e5f95
root@ThinkPad:/home/jiqing# docker stop $(docker ps -q) && docker rm $(docker ps -aq)
0a9d3b5e5f95
0a9d3b5e5f95

Remove non-running containers

# docker container prune
WARNING! This will remove all stopped containers.
Are you sure you want to continue? [y/N] y
Deleted Containers:
38fcd72cc70b07c2ca991e4f7681d192c24f9e89c96f48f9a1505cb736beecc7

Total reclaimed space: 0B

Delete all mirrors (be careful)

# docker rmi $(docker images -q)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325473911&siteId=291194637