[BUG] `watch` rebuilds in an endless loop when the watched path contains `.git`
维护者通常 1 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 70/100
调研方向
从 pkg/compose/watch.go 中添加 .git/ 忽略规则的两个 watch.NewDockerPatternMatcher 调用处开始。检查模式如何与基路径拼接,并将匹配结果与 issue 中描述的完整事件路径进行比较;报告称 **/.git 会停止循环。更新忽略模式并验证:编辑源文件会触发一次重建,而 .git 的更改会被忽略。
由索引模型根据 Issue 内容生成。
描述
Description
With a rebuild watch rule whose path contains the repository's .git directory (for example path: . in a project at the repository root), a single source edit makes docker compose watch rebuild over and over: about 30 rebuilds in 30 seconds, and it never stops. An empty git commit starts the same loop. With a sync rule, git operations sync the .git contents into the container.
.git/ is meant to be always ignored (pkg/compose/watch.go adds a hardcoded .git/ ignore rule), but that rule never matches inside the project. Every build then feeds the loop: buildx reads the git state of the build context for provenance and updates .git while doing so, and watch sees that as a new change.
Expected: changes under .git/ are ignored, so one edit triggers one rebuild.
Workaround: add .git to .dockerignore, or set BUILDX_GIT_INFO=0.
Expected: changes under .git/ inside the watched path are ignored.
Steps To Reproduce
# Dockerfile
FROM alpine
COPY app.txt /app.txt
CMD ["sleep", "infinity"]
# compose.yaml
services:
app:
build: .
init: true
develop:
watch:
- action: rebuild
path: .
$ echo hi > app.txt
$ git init -q && git add . && git commit -qm init
$ docker compose up -d --build
$ docker compose watch --no-up > /tmp/watch.log 2>&1 & # log outside the watched path
$ echo x >> app.txt # one edit
$ sleep 30; grep -c Rebuilding /tmp/watch.log
32
With nothing edited, the count stays at 0. With .git in .dockerignore or BUILDX_GIT_INFO=0, one edit gives 1.
Compose Version
Docker Compose version 5.0.1
Also reproduced on main (289d8a037).
buildx v0.30.1-desktop.1 (also v0.24.0)
Docker Environment
Docker Engine 29.1.3 (linux/arm64, Docker Desktop on macOS)
Anything else?
The rule is built with watch.NewDockerPatternMatcher("/", []string{".git/"}) in pkg/compose/watch.go (two places). Patterns are joined to the base path, so this becomes /.git/ and only matches a .git at the filesystem root. Events carry full paths such as /home/me/project/.git/index, so they never match.
With **/.git instead, a local build of main stops the loop: one edit gives 1 rebuild, an empty commit gives 0, and .git is no longer synced. **/.git matches .git and its contents at any depth, but not .gitignore or .github/.
#14217 changes the same ignore set (it excludes the Dockerfile and compose files) but does not touch .git.
- 主要语言
- Go
- 星标
- 38.4k
- 派生
- 5.9k
- 平均合并
- 2 天 1 小时
- 30 天内合并 PR
- 70
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
docker/compose 的其他 Issue
-
kind/feature
难度 4/5 3-5 天 新手友好度 48/100
docker/compose#14365 · 2 条评论 ·
维护者通常 1 天内回复
-
kind/feature
难度 5/5 一周以上 新手友好度 35/100
docker/compose#14356 · 1 条评论 ·
维护者通常 1 天内回复
-
Epic: Move service selection into the backend API instead of pre-filtering the project in the CLI未关闭
难度 5/5 一周以上 新手友好度 15/100
维护者通常 1 天内回复
-
Watch: exec mode可能已有人在做 @glours 于 9 天前认领。 未关闭kind/feature
docker/compose#14326 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Restore build concurrency limit now that bake supports it可能已有人在做 @maxproske 于 5 天前认领。 未关闭kind/feature
难度 3/5 1-2 天 新手友好度 35/100
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
grafana/tempo-operator#1691 ·
维护者通常 1 天内回复
-
enhancement
难度 1/5 1 小时以内 新手友好度 85/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
hashicorp/terraform-mcp-server#583 ·
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
-
backend bug low-priority
难度 2/5 1-3 小时 新手友好度 78/100
lognorman20/monaco#6225 ·