Commands you need when you test a docker image or build a lot of them and you see some dead images floating taking up space in your system.


Kill all running docker containers

docker rm -f $(docker ps -a -q)

See dangling docker containers

docker images -q --filter "dangling=true"

Remove untagged docker images

docker rmi -f `docker images -q --filter "dangling=true"`

Bash aliases

Save them one single file and run simple commands, for example:

alias docker.kill='docker rm -f $(docker ps -a -q)'
alias docker.dangling='docker images -q --filter "dangling=true"'
alias docker.remove-untagged-images='docker rmi -f `docker.dangling` > /dev/null 2>&1 || echo "Nothing to remove"'
File: ~/.bash_aliases
When you use these aliases make sure you enable them in your .profile xor .bashrc
if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
Snippet: ~/.bashrc