Files
nexus/raw/Home Office/如何删除旧的废弃的docker container +volume.md

129 lines
2.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: ✅ 最常用:删除旧 Portainer Container + Volume
source:
author: shenwei
published:
created:
description:
tags: [container, docker, portainer, volume]
---
#docker #container #volume #portainer
```table-of-contents
```
# ✅ 最常用:删除旧 Portainer Container + Volume
### 1. **查看现有 Portainer 容器**
```
docker ps -a | grep portainer
```
你会看到类似:
`bdadf357fb03 portainer/portainer-ce "/portainer" ...`
### 2. **停止容器**
```
docker stop portainer
```
或者:
```
docker stop bdadf357fb03
```
### 3. **删除容器**
```
docker rm portainer
```
或:
```
docker rm -f portainer
```
---
# 🧹 清理旧 Volume & Network (可选,但推荐)
### 4. **删除旧 Volume**
先查看:
```
docker volume ls | grep portainer
```
如果你看到:
`local portainer_data`
删除它:
```
docker volume rm portainer_data
```
> ⚠️ 注意:这会删除 Portainer 所有数据(用户、配置)。
> 如果你想保留数据,不要删 volume只需要在 compose 文件里加:
`external: true`
---
### 5. **删除旧 Network**
查看:
```
docker network ls | grep portainer
```
如果看到:
`portainer_network`
删除:
``` bash
docker network rm portainer_network
```
---
# 🧹 BONUS删除整个 Portainer 旧堆栈(如果是用 compose 部署的)
如果你之前是用 `docker compose` 运行的,可以直接:
``` bash
docker compose down
```
如果你的 compose 文件名不是默认 `docker-compose.yml`
``` bash
docker compose -f portainer-compose.yml down
```
---
# 🚀 最干净的重装流程
如果你想彻底重来一遍:
``` bash
docker stop portainer && docker rm portainer
docker volume rm portainer_data
docker network rm portainer_network
docker compose up -d
```
---
# 🧠 提前帮你想到:为什么会出现 WARN
你看到的两个警告完全正常,原因如下:
### ✔ **WARN 1Network 已存在但不是当前项目创建**
说明你之前用了别的 compose 文件部署过 Portainer。
解决方案:
- 要用旧 network → compose 里写 `external: true`
- 要重建 network → 删除旧 network上面已写
---
### ✔ **WARN 2Volume 已存在但属于另一个 compose 项目**
说明你以前用不同 project 名字做过 Portainer。
解决方案同上。