a066e6
% ".containerignore" "28" "Sep 2021" "" "Container User Manuals"
a066e6
a066e6
# NAME
a066e6
a066e6
.containerignore(.dockerignore) - files to ignore buildah or podman build context directory
a066e6
a066e6
# INTRODUCTION
a066e6
a066e6
Before container engines build an image, they look for a file named .containerignore or .dockerignore in the root
a066e6
context directory. If one of these file exists, the CLI modifies the context to exclude files and
a066e6
directories that match patterns specified in the file. This avoids adding them to images using the ADD or COPY
a066e6
instruction.
a066e6
a066e6
The CLI interprets the .containerignore or .dockerignore file as a newline-separated list of patterns similar to
a066e6
the file globs of Unix shells. For the purposes of matching, the root of the context is considered to be both the
a066e6
working and the root directory. For example, the patterns /foo/bar and foo/bar both exclude a file or directory
a066e6
named bar in the foo subdirectory of PATH or in the root of the git repository located at URL. Neither excludes
a066e6
anything else.
a066e6
a066e6
If a line in .containerignore or .dockerignore file starts with # in column 1, then this line is considered as a
a066e6
comment and is ignored before interpreted by the CLI.
a066e6
a066e6
# EXAMPLES
a066e6
a066e6
Here is an example .containerignore file:
a066e6
a066e6
```
a066e6
# comment
a066e6
*/temp*
a066e6
*/*/temp*
a066e6
temp?
a066e6
```
a066e6
a066e6
This file causes the following build behavior:
a066e6
Rule 	Behavior
a066e6
```
a066e6
# comment 	Ignored.
a066e6
*/temp* 	Exclude files and directories whose names start with temp in any immediate subdirectory of the root.
a066e6
For example, the plain file /somedir/temporary.txt is excluded, as is the directory /somedir/temp.
a066e6
*/*/temp* 	Exclude files and directories starting with temp from any subdirectory that is two levels below the
a066e6
root. For example, /somedir/subdir/temporary.txt is excluded.
a066e6
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.
a066e6
```
a066e6
Matching is done using Go’s filepath.Match rules. A preprocessing step removes leading and trailing whitespace and
a066e6
eliminates . and .. elements using Go’s filepath.Clean. Lines that are blank after preprocessing are ignored.
a066e6
a066e6
Beyond Go’s filepath.Match rules, Docker also supports a special wildcard string ** that matches any number of
a066e6
directories (including zero). For example, **/*.go will exclude all files that end with .go that are found in all
a066e6
directories, including the root of the build context.
a066e6
a066e6
Lines starting with ! (exclamation mark) can be used to make exceptions to exclusions. The following is an example .containerignore file that uses this mechanism:
a066e6
```
a066e6
*.md
a066e6
!README.md
a066e6
```
a066e6
All markdown files except README.md are excluded from the context.
a066e6
a066e6
The placement of ! exception rules influences the behavior: the last line of the .containerignore that matches a
a066e6
particular file determines whether it is included or excluded. Consider the following example:
a066e6
```
a066e6
*.md
a066e6
!README*.md
a066e6
README-secret.md
a066e6
```
a066e6
No markdown files are included in the context except README files other than README-secret.md.
a066e6
a066e6
Now consider this example:
a066e6
```
a066e6
*.md
a066e6
README-secret.md
a066e6
!README*.md
a066e6
```
a066e6
All of the README files are included. The middle line has no effect because !README*.md matches README-secret.md and
a066e6
comes last.
a066e6
a066e6
You can even use the .containerignore file to exclude the Containerfile or Dockerfile and .containerignore files.
a066e6
These files are still sent to the daemon because it needs them to do its job. But the ADD and COPY instructions do
a066e6
not copy them to the image.
a066e6
a066e6
Finally, you may want to specify which files to include in the context, rather than which to exclude. To achieve
a066e6
this, specify * as the first pattern, followed by one or more ! exception patterns.
a066e6
a066e6
## SEE ALSO
a066e6
buildah-build(1), podman-build(1), docker-build(1)
a066e6
a066e6
# HISTORY
a066e6
*Sep 2021, Compiled by Dan Walsh (dwalsh at redhat dot com) based on docker.com .dockerignore documentation.