Post

Handy Docker commands

Harianto van Insulinde

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.

Commands

Kill all running docker containers

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

See dangling docker containers

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

Remove untagged docker images

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

Bash aliases

Save them one single file and run simple commands, for example:
docker.remove-untagged-images

bash
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

bash
if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

Snippet: ~/.bashrc