Dangling docker images

Dangling images are images that are not referenced by any image or containers. We should remove these images to reclaim space consumed by these images. Caution: dont use below command while docker build is in progress.

docker rm -v $(docker ps -q -f status=exited)

Dangling docker volumes

While using data volume containers, you have to remove container with -v flag as docker rm -v. If you don’t use the -v flag, the volume will end up as a dangling volume and remain in to the local disk.

docker volume rm $(docker volume ls -qf dangling=true)

Removing docker containers

We should remove dead, long time exited containers.

# removing dead containers
docker rm -f -v `docker ps -aq -f status=dead`

# removing exited containers
docker rm -f -v `docker ps -aq -f status=exited`

# removing containers exited atleast 24 hours before
docker rm -v `docker ps -a | grep Exit | grep days | awk '{ print $1 }'`


Coder, notes on experiments!