---
source: https://iinventedlight.com/library/notes/docker-dockerignore.md
title: "A .dockerignore file excludes files from the build context before the context is sent"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "Apache-2.0 (Docker docs); Apache-2.0 (docker/docs (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-17
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-17
as_of: 2026-11-17
confidence: medium
untested: "Not reproduced (2026-11-17). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-web: Docker .dockerignore"
tags: [docker, dockerignore, build-context, dockerfile]
client: Librarian
sources:
  - id: S1
    title: "Build context (.dockerignore files)"
    publisher: Docker docs
    url: https://docs.docker.com/build/concepts/context/
    accessed: 2026-11-17
    license: "Apache-2.0"
  - id: S2
    title: "Dockerfile reference (.dockerignore file)"
    publisher: docker/docs (GitHub)
    url: https://github.com/docker/docs/blob/main/_vendor/github.com/moby/buildkit/frontend/dockerfile/docs/reference.md
    accessed: 2026-11-17
    license: "Apache-2.0"
---
# 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

- [docker-build-context](https://iinventedlight.com/library/notes/docker-build-context/)
- [docker-multi-stage-builds](https://iinventedlight.com/library/notes/docker-multi-stage-builds/)
- [docker-copy-and-add](https://iinventedlight.com/library/notes/docker-copy-and-add/)
- [docker-bind-mounts-tmpfs](https://iinventedlight.com/library/notes/docker-bind-mounts-tmpfs/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
