From 01a0f9718d4f6cc788fd988f9651959ad9c145df Mon Sep 17 00:00:00 2001 From: Plain <56195905+hanjie-chen@users.noreply.github.com> Date: Mon, 3 Feb 2025 16:46:59 +0800 Subject: [PATCH] Update file-watch.md: add ignore attribute path (#21820) ## Description I added some explanation about the `ignore` attribute in the watch rule. I noticed the document says: > All paths are relative to the project directory However, when I deployed it in my project, I found that my container was rebuilding crazily based on the action I defined. After testing, I discovered that the `ignore` path is actually relative to the `path` defined in the same `watch` rule, not the project directory. I also confirmed this with the AI on the Docker Docs website. This PR updates the documentation to clarify this behavior. --------- Co-authored-by: Allie Sadler <102604716+aevesdocker@users.noreply.github.com> Co-authored-by: Guillaume Lours <705411+glours@users.noreply.github.com> --- content/manuals/compose/how-tos/file-watch.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/content/manuals/compose/how-tos/file-watch.md b/content/manuals/compose/how-tos/file-watch.md index 9b22aa5ece..2af413a3b5 100644 --- a/content/manuals/compose/how-tos/file-watch.md +++ b/content/manuals/compose/how-tos/file-watch.md @@ -12,7 +12,7 @@ aliases: {{% include "compose/watch.md" %}} `watch` adheres to the following file path rules: -* All paths are relative to the project directory +* All paths are relative to the project directory, apart from ignore file patterns * Directories are watched recursively * Glob patterns aren't supported * Rules from `.dockerignore` apply @@ -114,6 +114,10 @@ For `path: ./app/html` and a change to `./app/html/index.html`: * `target: /app/static` -> `/app/static/index.html` * `target: /assets` -> `/assets/index.html` +### `ignore` + +The `ignore` patterns are relative to the `path` defined in the current `watch` action, not to the project directory. In the following Example 1, the ignore path would be relative to the `./web` directory specified in the `path` attribute. + ## Example 1 This minimal example targets a Node.js application with the following structure: @@ -121,7 +125,8 @@ This minimal example targets a Node.js application with the following structure: myproject/ ├── web/ │ ├── App.jsx -│ └── index.js +│ ├── index.js +│ └── node_modules/ ├── Dockerfile ├── compose.yaml └── package.json @@ -152,6 +157,8 @@ For example, `./web/App.jsx` is copied to `/src/web/App.jsx`. Once copied, the bundler updates the running application without a restart. +And in this case, the `ignore` rule would apply to `myproject/web/node_modules/`, not `myproject/node_modules/`. + Unlike source code files, adding a new dependency can’t be done on-the-fly, so whenever `package.json` is changed, Compose rebuilds the image and recreates the `web` service container.