---
source: https://iinventedlight.com/library/notes/docker-build-context.md
title: "Docker build context and the Dockerfile"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "Docker docs, Apache-2.0 (github.com/docker/docs; https://github.com/docker/docs/blob/main/LICENSE); Docker name and logo are trademarks of Docker Inc and are not licensed; prose restates or closely paraphrases cited source lines"
license_family: docker-docs-apache
rule_check: "needs rule check (family not in auto-publish rule; check.mjs auto-approves only usgov and arxiv-ccby)"
attribution: "Summary by iinventedlight (AI-assisted). Sources: Docker Docs, Build context, Docker docs, Apache-2.0 (github.com/docker/docs; https://github.com/docker/docs/blob/main/LICENSE); Docker name and logo are trademarks of Docker Inc and are not licensed; Docker Docs, Dockerfile overview, Docker docs, Apache-2.0 (github.com/docker/docs; https://github.com/docker/docs/blob/main/LICENSE); Docker name and logo are trademarks of Docker Inc and are not licensed."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-04
status: published
checked_on: 2026-11-04
as_of: 2026-11-04
confidence: medium
untested: "No code was run for this note; only the fetched documentation pages were read."
category: coding-references
topic_area: "code-ai-eng: Docker"
tags: ['docker', 'build', 'dockerfile', 'context']
sources:
  - id: S1
    title: "Build context"
    publisher: Docker Docs
    url: https://docs.docker.com/build/concepts/context/
    accessed: 2026-11-04
    license: "Docker docs, Apache-2.0 (github.com/docker/docs; https://github.com/docker/docs/blob/main/LICENSE); Docker name and logo are trademarks of Docker Inc and are not licensed"
  - id: S2
    title: "Dockerfile overview"
    publisher: Docker Docs
    url: https://docs.docker.com/build/concepts/dockerfile/
    accessed: 2026-11-04
    license: "Docker docs, Apache-2.0 (github.com/docker/docs; https://github.com/docker/docs/blob/main/LICENSE); Docker name and logo are trademarks of Docker Inc and are not licensed"
---
# Docker build context and the Dockerfile

**Answer:** The build context is the set of files that your build can access. Build instructions such as COPY and ADD can refer to any of the files and directories in the context. (S1)

## Kinds of context

- When your build context is a local directory, a remote Git repository, or a tar file, then that becomes the set of files that the builder can access during the build. (S1)
- When your build context is a plain-text file, the builder interprets the file as a Dockerfile, and the build doesn't use a filesystem context. (S1)
- To use a local build context, you can specify a relative or absolute filepath to the docker build command. (S1)
- The builder loads the files it needs from the build context when needed. (S1)
- You can also use local tarballs as build context, by piping the tarball contents to the docker build command. (S1)

## The Dockerfile

- Docker builds images by reading the instructions from a Dockerfile, a text file containing instructions for building your source code. (S2)
- The default filename to use for a Dockerfile is Dockerfile, without a file extension. (S2)
- RUN executes any commands in a new layer on top of the current image and commits the result. (S2)
- WORKDIR sets the working directory for any RUN, CMD, ENTRYPOINT, COPY, and ADD instructions that follow it in the Dockerfile. (S2)
- Each Dockerfile only has one CMD, and only the last CMD instance is respected when multiple exist. (S2)

## Claims
- id: C1
  claim: The build context is the set of files a build can access.
  source: S1
  evidence: "The build context is the set of files that your build can access."
- id: C2
  claim: A plain-text context is read as a Dockerfile.
  source: S1
  evidence: "the builder interprets the file as a Dockerfile."
- id: C3
  claim: The default Dockerfile name has no extension.
  source: S2
  evidence: "The default filename to use for a Dockerfile is Dockerfile, without a file extension."
- id: C4
  claim: Only the last CMD is respected.
  source: S2
  evidence: "and only the last CMD instance is respected when multiple exist."

## Sources
- [S1] Build context. Docker Docs. https://docs.docker.com/build/concepts/context/ . License: Docker docs, Apache-2.0 (github.com/docker/docs; https://github.com/docker/docs/blob/main/LICENSE); Docker name and logo are trademarks of Docker Inc and are not licensed. Accessed 2026-11-04.
- [S2] Dockerfile overview. Docker Docs. https://docs.docker.com/build/concepts/dockerfile/ . License: Docker docs, Apache-2.0 (github.com/docker/docs; https://github.com/docker/docs/blob/main/LICENSE); Docker name and logo are trademarks of Docker Inc and are not licensed. Accessed 2026-11-04.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
