Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Docker CLI Tips and Tricks

Docker Cli Tips and Tricks

My favorite command line options and best practices

My favorite command line aliases (quick container management, usually for local dev)

  • Only removes stopped containers, doesn't delete data volumes, mostly safe
    • alias drma='docker rm $(docker ps -aq)'
  • Remove all images, doesn't remove images in use by containers, mostly safe
    • alias drmi='docker rmi $(docker images -q -f "dangling=true")'
  • Remove all images, doesn't remove images in use by containers, mostly safe
    • alias drmai='docker rmi $(docker images -q)'
  • For Docker Machine users, set docker cli to use the default VM
    • alias drdefault='eval "$(docker-machine env default)"'
  • Execute interactive command in running container
    • alias drit='docker exec -it'
  • Get the IP for eth0 inside the container
    • alias drip='docker inspect --format="{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}"'

Other lists/dotfiles/functions for less typing

Cli filters for managing lots of images/containers

Filters

  • Filtering the image list
    • Only list dangling images (built with no name): docker images --filter "dangling=true"
  • Filtering the containers list
    • Only list containers that have exited successfully (without error): docker ps -a --filter 'exited=0'
    • Only list containers coming from nginx image: docker ps --filter ancestor=nginx

Formatting

Best list of all things Docker ecosystem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment