# 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
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dev-notes.vinguyen.blog/notes/deployment-and-operation/docker-container/clean-up-unused-docker-images.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
