docker/compose

Allow bind mount and watch at the same time

Closed this issue · 1 comments

Description

I would like to use a bind mount to sync a very large directory, which is a bit more robust than using file watches. File watches tend to miss changes, especially when it is watching thousands of files. In that large directory are a few files (pypoetry.toml and poetry.lock) that need to trigger a rebuild. Right now, it's impossible to combine a global bind mount with some small rebuild watches, because it triggers the following warning, which skips the watch:

WARN[0004] path '/project/pyproject.toml' also declared by a bind mount volume, this path won't be monitored!

The reason for this warning, is to help the user create a sane compose.yaml file, by not allowing this overlap. I think we can find a middle ground. Instead of disallowing it, this should just perform the watch anyway, but still log a message.

I just found the PR that introduced this warning in the first place: #10741

My understanding of the warning was not entirely correct: it is not just to help you with writing a "sane" compose.yaml file, but overlapping watches and mounts can actually lead to an infinite loop of sync events.

This suggests a different solution: allow a combination of a bind mount and watch, only if the watch is of type "rebuild", because that combination could never lead to such an infinite loop and is therefore a legitimate configuration. The other types ("sync" and "sync+restart") should still result in the original warning + skip.

I'll decline the PR and make a new one.