teodoro
teodoro

Reputation: 257

Docker : Cannot remove dangling containers

when i try to execute a command to list all the dead or dangling docker in volume and delete it directly :

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

and it will throw an exception which is :

Unable to remove a directory of out the Docker root /var/lib/docker: /home/docker/volumes/ffdffa840a2fb54799aab3de565d02458915f460dc785b7288926729251e1b61/_data

Upvotes: 2

Views: 1347

Answers (2)

Qiu Yuzhou
Qiu Yuzhou

Reputation: 61

Same issue, below work for me

cd /home/docker/volumes/
rm -rf $(docker volume ls -qf dangling=true)

Upvotes: 1

Dirk is no longer here
Dirk is no longer here

Reputation: 368647

Might be a known issue. I have this little helper for some time now:

#!/bin/bash

imgs=$(docker images | awk '/<none>/ { print $3 }')
if [ "${imgs}" != "" ]; then
   echo docker rmi ${imgs}
   docker rmi ${imgs}
else
   echo "No images to remove"
fi

procs=$(docker ps -a -q --no-trunc)
if [ "${procs}" != "" ]; then
   echo docker rm ${procs}
   docker rm ${procs}
else
   echo "No processes to purge"
fi

Running it at most twice in succession seems to clean up most issues. I think I wrote it based on some blog posts two+ years ago.

Upvotes: 0

Related Questions