Skip to content

Instantly share code, notes, and snippets.

@patrickskim
Last active June 13, 2017 17:04
Show Gist options
  • Save patrickskim/6b26f7006241db87a16a25bda41b7bfd to your computer and use it in GitHub Desktop.
Save patrickskim/6b26f7006241db87a16a25bda41b7bfd to your computer and use it in GitHub Desktop.
Remove Docker containers & images

List all exited containers

docker ps -aq -f status=exited

Remove stopped containers

docker ps -aq --no-trunc | xargs docker rm This command will not remove running containers, only an error message will be printed out for each of them.

Remove dangling/untagged images

docker images -q --filter dangling=true | xargs docker rmi

Remove containers created after a specific container

docker ps --since a1bz3768ez7g -q | xargs docker rm

Remove containers created before a specific container

docker ps --before a1bz3768ez7g -q | xargs docker rm Use --rm for docker build Use --rm together with docker build to remove intermediary images during the build process.

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