Docker remove ALL volumes not attached

Docker can be tricky to debug. There’s instances where after upgrading a container the volume that was previously attached fails to work.

In this case it was a dev image and the quickest, and dirtiest, option was to clear out and rebuild. I could go one by one to delete the specific volumes.

docker volume ls
docker volume rm {specific_docker_container}

Instead I chose to delete all volumes not currently in use. This worked for my use case as I only have two dockers setups, left the one I wanted to keep running while executing the following commands.

docker volume rm `docker volume ls -q -f dangling=true`

grep without filenames

I needed to grep a directory, and sub directories, and not displaying the filenames in the output. This is when the man page came to the rescue.

man grep | grep filename


       -H, --with-filename
       -h, --no-filename

There we go, -h, –no-filename, is what I needed.

Example with output to a file:

grep -r "searching-for-this" . --no-filename > /tmp/test.txt