docker bulk delete mirrored container

When we built and tested docker, often produce a lot of useless mirrors or containers, we can use the following two commands to delete one by one.

docker container rm container id # delete container 
docker image rm remove a mirror image ID #

However, you can also use these commands to get the container ID and the ID of the mirror to achieve bulk delete

Gets the container ID list:

docker container ls -a -q

 Mirroring get a list of ID:

docker image ls -a -q

 Ultimately batch delete command

Batch delete container:

docker   container   rm  $(docker  container  ls   -a  -q)

 Batch delete image :( caution)

docker  image   rm   $(docker  image  ls   -a  -q)

 Batch delete container vessels will not start for deletion

But will complain

Error response from daemon: You cannot remove a running container .... Stop the container before attempting removal or force remove

If you want to remove all container vessel can first of all stop making bulk deletion

Stop bulk container command:

docker container   stop   $(docker  container  ls   -a  -q)

 

Guess you like

Origin www.cnblogs.com/kala00k/p/11183279.html