Skip to content

Instantly share code, notes, and snippets.

@lcaballero
Created September 18, 2019 20:49
Show Gist options
  • Save lcaballero/79ae53eb1b2a3e8f5f9065901d2ff312 to your computer and use it in GitHub Desktop.
Save lcaballero/79ae53eb1b2a3e8f5f9065901d2ff312 to your computer and use it in GitHub Desktop.
Docker tricks

Docker CLI Tricks

Reference URL: https://medium.com/@clasikas/docker-tips-tricks-or-just-useful-commands-6e1fd8220450

All existing containers (not only running)

docker ps     # show only running
docker ps -a  # show all containers

Remove all containers with status=exited

docker rm $(docker ps -q -f status=exited)

Stop all containers

docker stop $(docker ps -q)  # will run stop only for active containers
docker stop $(docker ps -aq) # will run stop for all

remove all docker images

docker rmi $(docker images -q)

Execute command in container

docker exec <YOUR_CONTAINER> echo "Hello from container!"

Possible docker aliases

alias dr='docker rm $(docker ps -aq)'
alias ds='docker stop $(docker ps -aq)'
alias di='docker images'
alias dri='docker rmi $(docker images -q)'
alias dsr='ds && dr'
alias dps='docker ps -a'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment