Files
nexus/wiki/concepts/容器重启策略.md
2026-04-22 04:03:04 +08:00

27 lines
1.0 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.
# 容器重启策略
## Description
Docker 容器的 `restart` 策略决定容器在退出后何时自动重启。通过设置合适的重启策略,可以实现服务的高可用和自愈能力,无需 systemd/supervisor 等进程管理器。
## 策略选项
| 策略 | 行为 |
|------|------|
| `no` | 不自动重启(默认) |
| `always` | 容器退出后始终重启 |
| `unless-stopped` | 除非被手动停止,否则始终重启 |
| `on-failure[:n]` | 仅在退出码非零时重启,最多 n 次 |
## 推荐场景
- **Web 服务**it-tools, Jellyfin, Navidrome`unless-stopped`
- **一次性任务**`no`
- **守护进程**:需要精确控制时用 `on-failure`
- **关键基础设施**(数据库):`always`
## `unless-stopped` vs `always`
- `always`:即使手动 `docker stop`Docker 守护进程重启后也会重启容器
- `unless-stopped`:手动 `docker stop` 后,守护进程重启不会自动重启该容器
## Used By
- [[用docker安装it-tools]] — `restart: unless-stopped`
- [[Docker-Compose]]