docker-watch-mode-2025
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDocker Compose Watch Mode (2025 GA)
Docker Compose Watch 模式(2025年正式发布)
Docker Compose Watch enables automatic hot reload during local development by synchronizing file changes instantly without manual container restarts.
Docker Compose Watch 可在本地开发期间实现自动热重载,无需手动重启容器,就能即时同步文件变更。
Three Watch Actions
三种Watch操作
1. sync - Hot Reload
1. sync - 热重载
For frameworks with hot reload (React, Next.js, Node.js, Flask).
Copies changed files directly into running container.
适用于支持热重载的框架(React、Next.js、Node.js、Flask)。
将变更的文件直接复制到运行中的容器内。
2. rebuild - Compilation
2. rebuild - 编译
For compiled languages (Go, Rust, Java) or dependency changes.
Rebuilds image and recreates container when files change.
适用于编译型语言(Go、Rust、Java)或依赖变更场景。
当文件变更时,重新构建镜像并重新创建容器。
3. sync+restart - Config Changes
3. sync+restart - 配置变更
For configuration files requiring restart.
Syncs files and restarts container.
适用于需要重启的配置文件。
同步文件并重启容器。
Usage
使用方式
yaml
services:
frontend:
build: ./frontend
develop:
watch:
- action: sync
path: ./frontend/src
target: /app/src
ignore: [node_modules/, .git/]
- action: rebuild
path: ./frontend/package.jsonStart with:
docker compose up --watchyaml
services:
frontend:
build: ./frontend
develop:
watch:
- action: sync
path: ./frontend/src
target: /app/src
ignore: [node_modules/, .git/]
- action: rebuild
path: ./frontend/package.json启动命令:
docker compose up --watchBenefits
优势
- Better performance than bind mounts
- No file permission issues
- Intelligent syncing
- Supports rebuild capability
- Works on all platforms
- 性能优于绑定挂载
- 无文件权限问题
- 智能同步
- 支持重建功能
- 全平台兼容