← All notes

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

Sources

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

Permanent ID: iil:note:4f17t5g9

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.},
}

Markdown

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.