Useful Docker Aliases

When using docker I have a number of aliases set up that I find useful for managing containers and images. I've collated these from long forgotten sources online.

Stop Typing Sudo

alias docker='sudo docker'

Stop All Containers

The following alias will stop all active containers. This is useful in dev in order to rebuild containers, and saves having to go through each container one by one to stop it.

alias docker-stop-all-containers='docker stop $(docker ps -a -q)'

Remove All Containers

This removes all of the containers. This is useful if you wish to clean up space used by containers prior to a rebuild, in particular on a dev system with multiple projects.

alias docker-rm-all-containers='docker rm $(docker ps -a -q)'

Note that unless the images are also removed, see below, a rebuild will be essentially cached unless the Docker file was changed.

Remove All Images

This removes all of the images. This means that when a container is rebuilt container images will have to be re-fetched. Cleaning the images will save on disk space if you have lots of old containers lying around.

alias docker-rm-all-containers='docker rm $(docker ps -a -q)'

0 Comments

No one has commented on this page yet.
Post your comment