mirror of
https://github.com/yeasy/docker_practice.git
synced 2026-03-11 04:14:38 +00:00
Continue to fix format issues
This commit is contained in:
@@ -198,17 +198,29 @@ CONTAINER ID IMAGE STATUS NAMES
|
||||
| **适用场景** | 调试、临时操作 | 查看主进程输出 |
|
||||
| **推荐程度** | ✅ 推荐 | ⚠️ 特殊场景使用 |
|
||||
|
||||
```
|
||||
docker exec docker attach
|
||||
┌─────────────────────┐ ┌─────────────────────┐
|
||||
│ 容器 │ │ 容器 │
|
||||
│ ┌───────────────┐ │ │ ┌───────────────┐ │
|
||||
│ │ PID 1: nginx │ │ │ │ PID 1: bash │◄─┼── 附加到主进程
|
||||
│ ├───────────────┤ │ │ └───────────────┘ │
|
||||
│ │ PID 50: bash │◄─┼── 新进程 │ │
|
||||
│ └───────────────┘ │ │ │
|
||||
└─────────────────────┘ └─────────────────────┘
|
||||
退出 bash 不影响 nginx 退出 bash 容器停止
|
||||
```mermaid
|
||||
flowchart LR
|
||||
subgraph Exec ["docker exec"]
|
||||
direction TB
|
||||
subgraph Container1 ["容器"]
|
||||
E_PID1["PID 1: nginx"]
|
||||
E_PID50["PID 50: bash"]
|
||||
end
|
||||
NewProc["新进程"] -- 附加到 --> E_PID50
|
||||
end
|
||||
|
||||
subgraph Attach ["docker attach"]
|
||||
direction TB
|
||||
subgraph Container2 ["容器"]
|
||||
A_PID1["PID 1: bash"]
|
||||
end
|
||||
MainProc["附加到主进程"] --> A_PID1
|
||||
end
|
||||
|
||||
note1["退出 bash 不影响 nginx"]
|
||||
note2["退出 bash 容器停止"]
|
||||
Container1 -.-> note1
|
||||
Container2 -.-> note2
|
||||
```
|
||||
|
||||
---
|
||||
@@ -280,17 +292,3 @@ $ docker exec -u root -it myapp bash
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 本章小结
|
||||
|
||||
| 需求 | 推荐命令 |
|
||||
|------|---------|
|
||||
| 进入容器调试 | `docker exec -it 容器名 bash` |
|
||||
| 执行单条命令 | `docker exec 容器名 命令` |
|
||||
| 查看主进程输出 | `docker attach 容器名`(慎用) |
|
||||
|
||||
### 延伸阅读
|
||||
|
||||
- [后台运行](5.2_daemon.md):理解容器主进程
|
||||
- [查看容器](5.1_run.md):列出和过滤容器
|
||||
- [容器日志](5.2_daemon.md):查看容器输出
|
||||
|
||||
Reference in New Issue
Block a user