Files
nexus/wiki/concepts/Docker-Compose.md
2026-04-22 08:02:59 +08:00

71 lines
2.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.
# Docker Compose
## Description
Docker Compose 是 Docker 官方提供的多容器 Docker 应用定义和运行工具。通过 `docker-compose.yml`(或 `compose.yaml`)配置文件,使用 YAML 格式声明式定义多容器服务的网络、卷、端口映射、环境变量等,实现一键部署复杂应用。
## Version
- **V1 (独立包)**`docker-compose` 命令(已弃用)
- **V2 (插件)**`docker compose` 命令(当前主流),通过 `docker-compose-plugin` 包安装,集成到 Docker CLI
## V1 vs V2 Command Reference
| V1 (独立包) | V2 (插件) |
|------------|-----------|
| `docker-compose up -d` | `docker compose up -d` |
| `docker-compose ps` | `docker compose ps` |
| `docker-compose down` | `docker compose down` |
| `docker-compose -f xxx.yml config` | `docker compose -f xxx.yml config` |
## Core Concepts
- **Services**: 定义每个容器服务(镜像、构建、端口、卷、环境变量)
- **Volumes**: 命名数据卷,持久化容器数据
- **Networks**: 容器网络配置bridge、host、overlay
- **Version**: `version: '3.8'` 为当前主流版本规范
## Example
```yaml
version: '3.8'
services:
it-tools:
image: corentinth/it-tools:latest
container_name: it-tools
restart: unless-stopped
stdin_open: true
tty: true
ports:
- "8999:80"
deploy:
resources:
limits:
memory: 128M
```
## Used By
- [[用docker安装it-tools]]
- [[用docker安装transmission]]
- [[如何删除旧的废弃的docker-container-volume]]
- [[Navidrome]]
- [[Jellyfin]]
- [[RSSHub]]
- [[Portainer]]
## External Mode
Compose 文件中声明 `external: true` 可让 Docker 复用已存在的 Volume 或 Network 而非创建新的,避免重装时的命名冲突警告:
```yaml
volumes:
portainer_data:
external: true
networks:
portainer_network:
external: true
```
## Related Concepts
- [[Docker-Image]]
- [[Docker-Save]]
- [[Docker-Load]]
- [[容器资源限制]]
- [[容器重启策略]]
- [[端口映射]]
- [[桥接网络]]