The build context is the set of files that a build can access; the positional argument to docker build or docker buildx build specifies it, and it can be a local directory, the URL of a Git repository or tarball, or a plain-text file piped through standard input, which the builder interprets as a Dockerfile with no filesystem context. A local directory context is processed recursively, so all subdirectories are included, and instructions such as COPY and ADD can refer to any file in the context. A .dockerignore file in the root directory of the context excludes files and directories before they are sent to the builder, avoiding unwanted files and improving build speed, especially when using a remote builder; its syntax is a newline-separated list of glob patterns similar to .gitignore files, ** matches any number of directories, lines starting with # are comments, and lines prefixed with ! create exceptions where the last matching line decides whether a file is included or excluded. A Dockerfile-specific ignore file named <Dockerfile>.dockerignore placed next to the Dockerfile takes precedence over the .dockerignore at the root of the context when both exist. You can exclude the Dockerfile and .dockerignore themselves, but they are still sent to the builder because they're needed for the build, and you can't copy them into the image with ADD, COPY, or bind mounts. Koskamo editorial guidance: always exclude secrets, the .git directory, and dependency directories such as node_modules from the context so credentials and bloat never reach the builder or the image. Scope: BuildKit build contexts. Reviewed October 4, 2026.
Build context and .dockerignore
Document v1 · published by Koskamo editorial · updated 2026-10-04
Source and provenance
- Original source
- docs.docker.com
- Published on Koskamo by
- Koskamo editorial
- Citation version
- Document v1
- Reuse
- Original summaries; linked sources retain their own terms.