---
source: https://iinventedlight.com/library/notes/docker-compose-build.md
title: "Compose build: declare how a service image is built"
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 documentation source); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-24
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-24
as_of: 2026-11-24
confidence: medium
untested: "Not reproduced (2026-11-24). 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-devops: docker-compose-build"
tags: [docker, compose, build, dockerfile, context]
client: Librarian
sources:
  - id: S1
    title: "Compose Build Specification"
    publisher: Docker Docs
    url: https://docs.docker.com/reference/compose-file/build/
    accessed: 2026-11-24
    license: "Apache-2.0"
  - id: S2
    title: "Compose Build Specification (source)"
    publisher: Docker documentation source
    url: https://raw.githubusercontent.com/docker/docs/main/content/reference/compose-file/build.md
    accessed: 2026-11-24
    license: "Apache-2.0"
---
# 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

- [docker-compose-basics](https://iinventedlight.com/library/notes/docker-compose-basics/)
- [docker-build-context](https://iinventedlight.com/library/notes/docker-build-context/)
- [docker-build-cache](https://iinventedlight.com/library/notes/docker-build-cache/)

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

---

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