Compose build: declare how a service image is built
Answer: The optional build key describes, in a portable Compose file, how to rebuild an application from source.
String or object
You may give build as a context path string, or as a detailed build definition.
A string path becomes the Docker context for the build.
Compose then expects a canonical Dockerfile at the directory root.
A detailed object can name build arguments and an alternate Dockerfile location.
Paths
Paths may be absolute or relative in either form.
Relative paths start from the directory that contains the Compose file.
An absolute path is not portable, and Compose displays a warning.
The spec also explains using build and image together.
See also
Claims
- id: C1 claim: Build tells Compose how to rebuild an application from source. source: S1 evidence: "tells Compose how to (re)build an application from source"
- id: C2 claim: Build may be a context path string or a detailed definition. source: S1 evidence: "a single string defining a context path, or as a detailed build definition"
- id: C3 claim: A string path looks for a Dockerfile at the directory root. source: S2 evidence: "at the root of the directory"
- id: C4 claim: A relative path is resolved from the Compose file directory. source: S2 evidence: "it is resolved from the directory containing your Compose file"
Sources
- [S1] Compose Build Specification. Docker Docs. https://docs.docker.com/reference/compose-file/build/ . License: Apache-2.0. Accessed 2026-11-24.
- [S2] Compose Build Specification (source). Docker documentation source. https://raw.githubusercontent.com/docker/docs/main/content/reference/compose-file/build.md . License: Apache-2.0. Accessed 2026-11-24.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Docker Docs, Compose Build Specification; Docker documentation source, Compose Build Specification (source). Apache-2.0 (https://raw.githubusercontent.com/docker/docs/main/LICENSE). Copyright Docker, Inc. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Docker Docs, Compose Build Specification; Docker documentation source, Compose Build Specification (source). Apache-2.0 (https://raw.githubusercontent.com/docker/docs/main/LICENSE). Copyright Docker, Inc.
Cite this
iinventedlight. 2026. "Compose build: declare how a service image is built." iinventedlight Library, iil:note:78jdjq5h, version of 2026-11-24. https://iinventedlight.com/library/notes/docker-compose-build/. License: CC-BY-4.0.
@misc{iil_note_78jdjq5h,
author = {{iinventedlight}},
title = {{Compose build: declare how a service image is built}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-24},
url = {https://iinventedlight.com/library/notes/docker-compose-build/},
note = {Permanent ID iil:note:78jdjq5h. 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).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- docker-compose-build.schema.json (schema; CC-BY-4.0)
- docker-compose-build.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/docker-compose-build.md.