Skip to content

Instantly share code, notes, and snippets.

@materkel
Last active May 16, 2016 19:06
Show Gist options
  • Save materkel/a0ea34584540f8e82ae4 to your computer and use it in GitHub Desktop.
Save materkel/a0ea34584540f8e82ae4 to your computer and use it in GitHub Desktop.
collection of useful docker commands
#!/bin/bash
# Get IP Address of all containers
docker inspect -f '{{.Name}} - {{.NetworkSettings.IPAddress }}' $(docker ps -aq)
# remove all containers
docker rm -f $(docker ps -aq)
# remove all images
docker rmi -f $(docker images -q)
# remove old containers
# http://stackoverflow.com/questions/17236796/how-to-remove-old-docker-containers
docker ps -a | grep 'weeks ago' | awk '{print $1}' | xargs --no-run-if-empty docker rm
# select all unused/untagged docker images
docker images -q -f "dangling=true"
# select all unused/untagged docker images exluding images 1 to 5
# credits to: http://www.commandlinefu.com/commands/view/9890/print-all-lines-between-two-line-numbers
docker images -q -f "dangling=true" | awk 'NR > 5'
# remove older unused images (unused images excluding the first 5)
docker rmi $(docker images -q -f "dangling=true" | awk 'NR > 5')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment