元数据
| id | docker-container-name-conflict | 收录 | 2026-08-31 |
|---|---|---|---|
| 问题域 | 编码代理与终端 | 主题分组 | 容器与 WSL |
| 适用工具 | docker · 外部工具 | ||
症状
```
docker: Error response from daemon: Conflict. The container name "/repro-conflict" is already in use by container "49e3c7e4...". You have to remove (or rename) that container to be able to reuse that name.
Run 'docker run --help' for more information
```
特征:`docker run --name` 第二次用同一个名字;报错里带完整的 `Conflict. The container name "..." is already in use` 原文和占名容器 id。
原因
容器名是 daemon 全局唯一资源,create 时登记、`rm` 时才释放,`stop` 不释放。同名二次创建直接 Conflict;`docker ps` 只显示运行中容器,容易误判「名字空闲」。
解法
1. `docker ps -a | grep <名字>` 找占名者;
2. 没用了就 `docker rm -f <名字>`;还有用就 `docker rename` 或换新名字;
3. 脚本/CI 养成习惯:先 `docker rm -f` 再 `docker run --name`(幂等),或加 `|| true` 容错。
验证证据
- 本地实测(2026-08-31,WSL Ubuntu,docker 29.1.3,alpine:latest):
- 链 A:`docker run -d --name repro-conflict alpine sleep 60` 成功(输出容器 id)→ 同命令再跑 → `docker: Error response from daemon: Conflict. The container name "/repro-conflict" is already in use by container "49e3c7e4..."`(exit 125);
- 链 B:`docker rm -f repro-conflict` 后同命令再跑 → 成功。
- 实测复现日志(2026-08-31)
来源与证据
素材来源:本站实测沉淀(2026-08-31)
验证证据:Evidence details kept locally (2026-08-31)