compose.yml 详解
完整结构
services:
web:
image: nginx:latest
build: .
ports:
- "8080:80"
volumes:
- ./html:/usr/share/nginx/html
environment:
- NODE_ENV=production
depends_on:
- app
restart: always
app:
build:
context: .
dockerfile: Dockerfile
ports:
- "3000:3000"
env_file:
- .env
networks:
- frontend
volumes:
db-data:
networks:
frontend:
常用字段
| 字段 | 说明 |
|---|---|
image | 使用镜像 |
build | 构建镜像 |
ports | 端口映射 |
volumes | 卷挂载 |
environment | 环境变量 |
depends_on | 依赖服务 |
restart | 重启策略 |
command | 覆盖启动命令 |
小结
compose.yml 是多容器应用的声明式配置。