> For the complete documentation index, see [llms.txt](https://dev-notes.vinguyen.blog/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dev-notes.vinguyen.blog/notes/deployment-and-operation/docker-container/clean-up-unused-docker-images.md).

# Clean up unused docker images

```bash
#!/bin/bash

# Remove all exited container
docker rm $(docker ps -q -f status=exited)

# Remove none tag images (image with tag <none>)
docker images | grep "<none>" | awk '{print $3}' |xargs docker rmi -f

# Remove all images that is not using by any running container
# note: docker ps --format {{.Image} -> List all images of running container then set it as grep pattern
docker images --format {{.Repository}}:{{.Tag}} | grep -vFf <(docker ps --format {{.Image}}) | xargs docker rmi -f
```
