Add new content and update versions

This commit is contained in:
yeasy
2026-04-19 22:35:33 -07:00
parent 1d780f70c5
commit b3d1508310
18 changed files with 122 additions and 31 deletions
+2
View File
@@ -117,3 +117,5 @@ $ docker compose run web python app.py
$ docker compose config
$ docker compose down
```
> 💡 `docker compose down` 默认会删除容器和网络 **保留数据卷**如需同时删除数据卷请使用 `docker compose down -v`
+35 -2
View File
@@ -493,7 +493,14 @@ mac_address: 08-00-27-00-0C-0A
```yaml
privileged: true
```
指定容器退出后的重启策略为始终重启该命令对保持服务始终运行十分有效在生产环境中推荐配置为 `always` 或者 `unless-stopped`
指定容器退出后的重启策略该命令对保持服务始终运行十分有效在生产环境中推荐配置为 `always` 或者 `unless-stopped`
| 策略 | 说明 |
|------|------|
| `no` | 默认值不自动重启 |
| `always` | 无论退出码如何始终重启Docker 守护进程启动时也会重启 |
| `on-failure[:max-retries]` | 仅在非零退出码时重启可指定最大重试次数 |
| `unless-stopped` | 类似 `always`但手动停止的容器在守护进程重启后不会自动启动 |
```yaml
restart: always
@@ -514,7 +521,33 @@ stdin_open: true
tty: true
```
### 11.5.34 读取变量
### 11.5.34 `profiles`
`profiles` 用于按场景选择性启动服务未指定 `profiles` 的服务默认始终启动标记了 `profiles` 的服务仅在激活对应 profile 时才启动
```yaml
services:
web:
image: nginx
debug:
image: busybox
profiles:
- debug
test:
image: node
profiles:
- test
```
启动时通过 `--profile` 激活
```bash
$ docker compose --profile debug up # 启动 web + debug
$ docker compose up # 仅启动 web
```
### 11.5.35 读取变量
Compose 模板文件支持动态读取主机的系统环境变量和当前目录下的 `.env` 文件中的变量