From 7d1479e1e1b640b7ba84bf661212e6d30704560b Mon Sep 17 00:00:00 2001 From: David Karlsson <35727626+dvdksn@users.noreply.github.com> Date: Fri, 7 Jun 2024 14:16:37 +0200 Subject: [PATCH] build(dockerignore): leading and trailing slashes are ignored Closes #20126 Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com> --- content/build/building/context.md | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/content/build/building/context.md b/content/build/building/context.md index 29bc048e12..9b47bc9c5e 100644 --- a/content/build/building/context.md +++ b/content/build/building/context.md @@ -464,15 +464,22 @@ file at the root of the build context if both exist. ### Syntax The `.dockerignore` file is a newline-separated list of patterns similar to the -file globs of Unix shells. For the purposes of matching, the root of the -context is considered to be both the working and the root directory. For -example, the patterns `/foo/bar` and `foo/bar` both exclude a file or directory -named `bar` in the `foo` subdirectory of `PATH` or in the root of the Git -repository located at `URL`. Neither excludes anything else. +file globs of Unix shells. Leading and trailing slashes in ignore patterns are +disregarded. The following patterns all exclude a file or directory named `bar` +in the subdirectory `foo` under the root of the build context: + +- `/foo/bar/` +- `/foo/bar` +- `foo/bar/` +- `foo/bar` If a line in `.dockerignore` file starts with `#` in column 1, then this line is considered as a comment and is ignored before interpreted by the CLI. +```gitignore +#/this/is/a/comment +``` + If you're interested in learning the precise details of the `.dockerignore` pattern matching logic, check out the [moby/patternmatcher repository](https://github.com/moby/patternmatcher/tree/main/ignorefile)