A .dockerignore file excludes files from the build context before the context is sent
Answer: You can use a .dockerignore file to exclude files or directories from the build context. When you run a build, the client looks for .dockerignore in the root directory of the context. Matching files and directories are removed from the context before it is sent to the builder.
Patterns and per-Dockerfile ignore files
The file is a newline-separated list of patterns, similar to Unix shell globs. Leading and trailing slashes in ignore patterns are disregarded. A line that starts with # in column 1 is a comment.
If you use multiple Dockerfiles, you can give each one its own ignore file. Place the ignore file next to the Dockerfile and prefix it with the Dockerfile name, such as build.Dockerfile.dockerignore. A Dockerfile-specific ignore file takes precedence over the root .dockerignore when both exist.
See also
Claims
- id: C1 claim: A .dockerignore file excludes files or directories from the build context. source: S1 evidence: "exclude files or directories from the"
- id: C2 claim: The client looks for .dockerignore in the root directory of the context. source: S1 evidence: "root directory of the context"
- id: C3 claim: The file is a newline-separated list of patterns. source: S1 evidence: "newline-separated list of patterns"
- id: C4 claim: The Dockerfile reference also documents using .dockerignore to exclude files from the context. source: S2 evidence: "exclude files and directories from the"
Sources
- [S1] Build context (.dockerignore files). Docker docs. https://docs.docker.com/build/concepts/context/ . License: Apache-2.0. Accessed 2026-11-17.
- [S2] Dockerfile reference (.dockerignore file). docker/docs (GitHub). https://github.com/docker/docs/blob/main/_vendor/github.com/moby/buildkit/frontend/dockerfile/docs/reference.md . License: Apache-2.0. Accessed 2026-11-17.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Docker docs, Build context (.dockerignore files), Apache-2.0 (https://github.com/docker/docs/blob/main/LICENSE); docker/docs (GitHub), Dockerfile reference (.dockerignore file), Apache-2.0 (https://github.com/docker/docs/blob/main/LICENSE). Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Docker docs, Build context (.dockerignore files), Apache-2.0 (https://github.com/docker/docs/blob/main/LICENSE); docker/docs (GitHub), Dockerfile reference (.dockerignore file), Apache-2.0 (https://github.com/docker/docs/blob/main/LICENSE).
Cite this
iinventedlight. 2026. "A .dockerignore file excludes files from the build context before the context is sent." iinventedlight Library, iil:note:4f17t5g9, version of 2026-11-17. https://iinventedlight.com/library/notes/docker-dockerignore/. License: CC-BY-4.0.
@misc{iil_note_4f17t5g9,
author = {{iinventedlight}},
title = {{A .dockerignore file excludes files from the build context before the context is sent}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-17},
url = {https://iinventedlight.com/library/notes/docker-dockerignore/},
note = {Permanent ID iil:note:4f17t5g9. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/docker-dockerignore.md.