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