Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pslobo/bffa3594672e5f076f30baad141dc0ff to your computer and use it in GitHub Desktop.
Save pslobo/bffa3594672e5f076f30baad141dc0ff to your computer and use it in GitHub Desktop.
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