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