mirror of
https://github.com/yeasy/docker_practice.git
synced 2026-03-11 04:14:38 +00:00
chore: remove unused historic image files
This commit is contained in:
@@ -28,6 +28,7 @@ hello world
|
||||
```
|
||||
|
||||
容器会把输出的结果 (STDOUT) 打印到宿主机上面。此时:
|
||||
|
||||
- 终端被占用,无法执行其他命令
|
||||
- 按 `Ctrl+C` 会终止容器
|
||||
- 关闭终端窗口,容器也会停止
|
||||
@@ -42,6 +43,7 @@ $ docker run -d ubuntu:24.04 /bin/sh -c "while true; do echo hello world; sleep
|
||||
```
|
||||
|
||||
使用 `-d` 参数后:
|
||||
|
||||
- 容器在后台运行
|
||||
- 返回容器的完整 ID
|
||||
- 终端立即释放,可以继续执行其他命令
|
||||
@@ -73,6 +75,7 @@ flowchart TD
|
||||
```
|
||||
|
||||
当你运行 `docker run -d ubuntu:24.04` 时:
|
||||
|
||||
1. 容器启动
|
||||
2. 没有指定命令,默认执行 `/bin/bash`
|
||||
3. 但没有交互式终端 (没有 `-it` 参数),bash 发现没有输入源
|
||||
@@ -80,11 +83,14 @@ flowchart TD
|
||||
5. 主进程退出,容器停止
|
||||
|
||||
**关键理解**:
|
||||
|
||||
- ❌ `-d` 参数**不是**让容器 “一直运行”
|
||||
- ✅ `-d` 参数是让容器 “在后台运行”,能运行多久取决于主进程
|
||||
|
||||
#### 常见的 “立即退出” 场景
|
||||
|
||||
相关信息如下表:
|
||||
|
||||
| 场景 | 原因 | 解决方案 |
|
||||
|------|------|---------|
|
||||
| `docker run -d ubuntu` | 默认 bash 无输入立即退出 | 指定长期运行的命令 |
|
||||
|
||||
Reference in New Issue
Block a user