> For the complete documentation index, see [llms.txt](https://docs.clore.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clore.ai/clore.ai/clore.ai-eng-zh/mian-xiang-zhu-ji-fang/server-offline-on-clore.ai/docker-disk-space-cleanup.md).

# Docker 磁盘空间清理

## Docker 磁盘空间清理（主机）

Docker 数据会随着时间在主机上不断增长。\
旧的租用会留下已停止的容器、未使用的镜像、卷和构建缓存。\
如果不清理，根磁盘会被占满，部署就会开始失败。

{% hint style="info" %}
仅在服务器处于 **未被租用** 并且你不需要任何旧的容器数据。\
如果你不确定，请先停在这里并检查磁盘使用情况。
{% endhint %}

***

## 1）检查磁盘使用情况

### 操作系统级磁盘空间（`df -h`)

这会显示每个已挂载文件系统的可用空间。

```bash
df -h
```

你主要关注 `/` （根分区）以及包含 `/var/lib/docker`.

### Docker 级磁盘使用情况（`docker system df`)

这会显示 Docker 正在存储什么，以及可回收多少空间。

```bash
docker system df
```

如果你想查看每个镜像/容器的更多细节：

```bash
docker system df -v
```

***

## 2）完整清理（推荐）

这是“重置前几次租用遗留的 Docker 内容”的命令。\
它会移除未使用的容器、镜像、网络，以及 **未使用的卷**.

```bash
docker system prune -a --volumes
```

{% hint style="warning" %}
`-a` 会移除 **所有未使用的镜像**，不只是“悬空”的镜像。\
这也包括你可能希望保留以便未来更快部署的缓存镜像。
{% endhint %}

***

## 3）单项清理命令（更可控）

当你只想清理某一类内容时使用这些命令。\
它们更适合渐进式维护，风险更低。

### 容器（仅已停止）

```bash
docker container prune
```

### 镜像（未使用）

仅移除悬空层：

```bash
docker image prune
```

移除所有未使用的镜像（风险与 `system prune -a`):

```bash
docker image prune -a
```

### 卷（未使用）

```bash
docker volume prune
```

### 网络（未使用）

```bash
docker network prune
```

***

## 4）主机维护最佳实践

1. 清理 **在租用之间** 或在计划停机期间。
2. 保留安全余量。\
   目标是 **10–20 GB** 始终在根磁盘上保留可用空间。
3. 定期检查 Docker 使用情况：
   * `df -h`
   * `docker system df`
4. 优先采用增量清理：
   * `docker container prune`
   * `docker image prune`
   * `docker volume prune`
5. 仅在必要时使用完整清理：
   * `docker system prune -a --volumes`
6. 如果磁盘使用量持续快速增长，请排查：
   * 租用者创建的大型卷。
   * 位于……下的日志 `/var/lib/docker/containers/*/*.log`.
   * 频繁重新构建镜像产生的构建缓存。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.clore.ai/clore.ai/clore.ai-eng-zh/mian-xiang-zhu-ji-fang/server-offline-on-clore.ai/docker-disk-space-cleanup.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
