Skip to content

Commit 01a0f97

Browse files
hanjie-chenaevesdockerglours
authored
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 <[email protected]> Co-authored-by: Guillaume Lours <[email protected]>
1 parent bdd2872 commit 01a0f97

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

content/manuals/compose/how-tos/file-watch.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ aliases:
1212
{{% include "compose/watch.md" %}}
1313

1414
`watch` adheres to the following file path rules:
15-
* All paths are relative to the project directory
15+
* All paths are relative to the project directory, apart from ignore file patterns
1616
* Directories are watched recursively
1717
* Glob patterns aren't supported
1818
* Rules from `.dockerignore` apply
@@ -114,14 +114,19 @@ For `path: ./app/html` and a change to `./app/html/index.html`:
114114
* `target: /app/static` -> `/app/static/index.html`
115115
* `target: /assets` -> `/assets/index.html`
116116

117+
### `ignore`
118+
119+
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.
120+
117121
## Example 1
118122

119123
This minimal example targets a Node.js application with the following structure:
120124
```text
121125
myproject/
122126
├── web/
123127
│ ├── App.jsx
124-
│ └── index.js
128+
│ ├── index.js
129+
│ └── node_modules/
125130
├── Dockerfile
126131
├── compose.yaml
127132
└── package.json
@@ -152,6 +157,8 @@ For example, `./web/App.jsx` is copied to `/src/web/App.jsx`.
152157

153158
Once copied, the bundler updates the running application without a restart.
154159

160+
And in this case, the `ignore` rule would apply to `myproject/web/node_modules/`, not `myproject/node_modules/`.
161+
155162
Unlike source code files, adding a new dependency can’t be done on-the-fly, so whenever `package.json` is changed, Compose
156163
rebuilds the image and recreates the `web` service container.
157164

0 commit comments

Comments
 (0)