# Docker 清理命令

[Docker命令大全](/docker/manual/docker-command-manual.md)

#### 杀死所有正在运行的容器

```shell
docker kill $(docker ps -a -q)
```

#### 删除所有已经停止的容器

```shell
docker rm $(docker ps -a -q)
```

#### 删除所有未打 dangling 标签的镜像

```shell
docker rmi $(docker images -q -f dangling=true)
```

#### 通过镜像的id来删除指定镜像

```shell
docker rmi <image id>
```

#### 删除所有镜像

```shell
docker rmi $(docker images -q)
```

#### 为这些命令创建别名

```shell
# ~/.bash_aliases

# 杀死所有正在运行的容器.
alias dockerkill='docker kill $(docker ps -a -q)'

# 删除所有已经停止的容器.
alias dockercleanc='docker rm $(docker ps -a -q)'

# 删除所有未打标签的镜像.
alias dockercleani='docker rmi $(docker images -q -f dangling=true)'

# 删除所有已经停止的容器和未打标签的镜像.
alias dockerclean='dockercleanc || true && dockercleani'
```


---

# 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://tuonioooo-notebook.gitbook.io/docker/manual/docker-clear-command.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.
