Skip to content

Instantly share code, notes, and snippets.

@aperezm-vlex
Created May 24, 2016 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aperezm-vlex/7df92f278e49c5633d4525c447c984b2 to your computer and use it in GitHub Desktop.
Save aperezm-vlex/7df92f278e49c5633d4525c447c984b2 to your computer and use it in GitHub Desktop.
Remove untagged docker images
#!/bin/bash
removeDockerImages () {
docker rmi $(docker images | grep "^<none>" | awk '{print $3}')
}
containersToRemove=$(removeDockerImages 2>&1 | grep "image is being used by stopped container" | sed 's/.*image is being used by stopped container//g')
if [[ ${#containersToRemove} > 0 ]]; then
docker rm $containersToRemove
removeDockerImages
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment