1.containerignore(28)        Container User Manuals        .containerignore(28)
2
3
4

NAME

6       .containerignore(.dockerignore)  -  files  to  ignore buildah or podman
7       build context directory
8
9
10

INTRODUCTION

12       Before container engines build an image, they look  for  a  file  named
13       .containerignore or .dockerignore in the root context directory. If one
14       of these file exists, the CLI modifies the context to exclude files and
15       directories  that  match  patterns  specified  in the file. This avoids
16       adding them to images using the ADD or COPY instruction.
17
18
19       The CLI interprets the .containerignore or .dockerignore file as a new‐
20       line-separated  list  of  patterns  similar  to  the file globs of Unix
21       shells. For the purposes of matching, the root of the context  is  con‐
22       sidered to be both the working and the root directory. For example, the
23       patterns /foo/bar and foo/bar both exclude a file  or  directory  named
24       bar  in  the foo subdirectory of PATH or in the root of the git reposi‐
25       tory located at URL. Neither excludes anything else.
26
27
28       If a line in .containerignore or .dockerignore file starts  with  #  in
29       column  1, then this line is considered as a comment and is ignored be‐
30       fore interpreted by the CLI.
31
32
33

EXAMPLES

35       Here is an example .containerignore file:
36
37
38              # comment
39              */temp*
40              */*/temp*
41              temp?
42
43
44
45       This file causes the following build behavior: Rule      Behavior
46
47
48              # comment      Ignored.
49              */temp*   Exclude files and directories whose names start with temp in any immediate subdirectory of the root.
50              For example, the plain file /somedir/temporary.txt is excluded, as is the directory /somedir/temp.
51              */*/temp*      Exclude files and directories starting with temp from any subdirectory that is two levels below the
52              root. For example, /somedir/subdir/temporary.txt is excluded.
53              temp?     Exclude files and directories in the root directory whose names are a one-character extension of temp. For example, /tempa and /tempb are excluded.
54
55
56
57       Matching is done using Go’s filepath.Match rules. A preprocessing  step
58       removes  leading  and  trailing whitespace and eliminates . and .. ele‐
59       ments using Go’s filepath.Clean. Lines that are blank after preprocess‐
60       ing are ignored.
61
62
63       Beyond  Go’s filepath.Match rules, Docker also supports a special wild‐
64       card string ** that matches any number of directories (including zero).
65       For  example,  */.go  will exclude all files that end with .go that are
66       found in all directories, including the root of the build context.
67
68
69       Lines starting with ! (exclamation mark) can be used to make exceptions
70       to  exclusions.  The following is an example .containerignore file that
71       uses this mechanism:
72
73
74              *.md
75              !README.md
76
77
78
79       All markdown files except README.md are excluded from the context.
80
81
82       The placement of ! exception rules influences the  behavior:  the  last
83       line  of the .containerignore that matches a particular file determines
84       whether it is included or excluded. Consider the following example:
85
86
87              *.md
88              !README*.md
89              README-secret.md
90
91
92
93       No markdown files are included in the context except README files other
94       than README-secret.md.
95
96
97       Now consider this example:
98
99
100              *.md
101              README-secret.md
102              !README*.md
103
104
105
106       All of the README files are included. The middle line has no effect be‐
107       cause !README*.md matches README-secret.md and comes last.
108
109
110       You can even use the .containerignore file to exclude the Containerfile
111       or  Dockerfile  and .containerignore files.  These files are still sent
112       to the daemon because it needs them to do its job. But the ADD and COPY
113       instructions do not copy them to the image.
114
115
116       Finally, you may want to specify which files to include in the context,
117       rather than which to exclude. To achieve this, specify * as  the  first
118       pattern, followed by one or more ! exception patterns.
119
120

SEE ALSO

122       buildah-build(1), podman-build(1), docker-build(1)
123
124
125

HISTORY

127       *Sep  2021,  Compiled  by Dan Walsh (dwalsh at redhat dot com) based on
128       docker.com .dockerignore documentation.
129
130
131
132                                   Sep 2021               .containerignore(28)
Impressum