Skip to content

Commit cbceafe

Browse files
authored
docs: address issue #24163 (#24177)
## Summary Removed repeated text about path behavior in the Compose Build Specification documentation. ## Changes - Consolidated duplicate sentences about absolute/relative path behavior that appeared in both the "former case" and "latter case" paragraphs - Improved clarity by explicitly referencing "When `build` is specified as a string" and "When `build` is specified as a detailed structure" instead of vague "former/latter" references - Added a single consolidated paragraph explaining path behavior that applies to both cases Fixes #24163 --- 🤖 Generated with [cagent](https://github.com/docker/cagent)
1 parent fc7ca0d commit cbceafe

1 file changed

Lines changed: 58 additions & 47 deletions

File tree

content/reference/compose-file/build.md

Lines changed: 58 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,30 @@
22
title: Compose Build Specification
33
description: Learn about the Compose Build Specification
44
keywords: compose, compose specification, compose file reference, compose build specification
5-
aliases:
6-
- /compose/compose-file/build/
5+
aliases:
6+
- /compose/compose-file/build/
77
weight: 130
88
---
99

1010
{{% include "compose/build.md" %}}
1111

12-
In the former case, the whole path is used as a Docker context to execute a Docker build, looking for a canonical
13-
`Dockerfile` at the root of the directory. The path can be absolute or relative. If it is relative, it is resolved
14-
from the directory containing your Compose file. If it is absolute, the path prevents the Compose file from being portable so Compose displays a warning.
12+
When `build` is specified as a string, the whole path is used as a
13+
Docker context to execute a Docker build, looking for a canonical
14+
`Dockerfile` at the root of the directory.
1515

16-
In the latter case, build arguments can be specified, including an alternate `Dockerfile` location. The path can be absolute or relative. If it is relative, it is resolved
17-
from the directory containing your Compose file. If it is absolute, the path prevents the Compose file from being portable so Compose displays a warning.
16+
When `build` is specified as a detailed structure, build arguments can
17+
be specified, including an alternate `Dockerfile` location.
1818

19-
## Using `build` and `image`
19+
In both cases, the path can be absolute or relative. If it is relative,
20+
it is resolved from the directory containing your Compose file. If it is
21+
absolute, the path prevents the Compose file from being portable so
22+
Compose displays a warning.
2023

21-
When Compose is confronted with both a `build` subsection for a service and an `image` attribute, it follows the rules defined by the [`pull_policy`](services.md#pull_policy) attribute.
24+
## Using `build` and `image`
2225

23-
If `pull_policy` is missing from the service definition, Compose attempts to pull the image first and then builds from source if the image isn't found in the registry or platform cache.
26+
When Compose is confronted with both a `build` subsection for a service and an `image` attribute, it follows the rules defined by the [`pull_policy`](services.md#pull_policy) attribute.
2427

28+
If `pull_policy` is missing from the service definition, Compose attempts to pull the image first and then builds from source if the image isn't found in the registry or platform cache.
2529

2630
## Publishing built images
2731

@@ -49,9 +53,9 @@ services:
4953
5054
When used to build service images from source, the Compose file creates three Docker images:
5155
52-
* `example/webapp`: A Docker image is built using `webapp` sub-directory, within the Compose file's folder, as the Docker build context. Lack of a `Dockerfile` within this folder returns an error.
53-
* `example/database`: A Docker image is built using `backend` sub-directory within the Compose file's folder. `backend.Dockerfile` file is used to define build steps, this file is searched relative to the context path, which means `..` resolves to the Compose file's folder, so `backend.Dockerfile` is a sibling file.
54-
* A Docker image is built using the `custom` directory with the user's `$HOME` as the Docker context. Compose displays a warning about the non-portable path used to build image.
56+
- `example/webapp`: A Docker image is built using `webapp` sub-directory, within the Compose file's folder, as the Docker build context. Lack of a `Dockerfile` within this folder returns an error.
57+
- `example/database`: A Docker image is built using `backend` sub-directory within the Compose file's folder. `backend.Dockerfile` file is used to define build steps, this file is searched relative to the context path, which means `..` resolves to the Compose file's folder, so `backend.Dockerfile` is a sibling file.
58+
- A Docker image is built using the `custom` directory with the user's `$HOME` as the Docker context. Compose displays a warning about the non-portable path used to build image.
5559

5660
On push, both `example/webapp` and `example/database` Docker images are pushed to the default registry. The `custom` service image is skipped as no `image` attribute is set and Compose displays a warning about this missing attribute.
5761

@@ -61,6 +65,7 @@ The `build` subsection defines configuration options that are applied by Compose
6165
`build` can be specified either as a string containing a path to the build context or as a detailed structure:
6266

6367
Using the string syntax, only the build context can be configured as either:
68+
6469
- A relative path to the Compose file's folder. This path must be a directory and must contain a `Dockerfile`
6570

6671
```yml
@@ -70,8 +75,8 @@ Using the string syntax, only the build context can be configured as either:
7075
```
7176

7277
- A Git repository URL. Git URLs accept context configuration in their fragment section, separated by a colon (`:`).
73-
The first part represents the reference that Git checks out, and can be either a branch, a tag, or a remote reference.
74-
The second part represents a subdirectory inside the repository that is used as a build context.
78+
The first part represents the reference that Git checks out, and can be either a branch, a tag, or a remote reference.
79+
The second part represents a subdirectory inside the repository that is used as a build context.
7580

7681
```yml
7782
services:
@@ -124,20 +129,20 @@ layers between service images.
124129

125130
```yaml
126131
services:
127-
base:
128-
build:
129-
context: .
130-
dockerfile_inline: |
131-
FROM alpine
132-
RUN ...
133-
my-service:
134-
build:
135-
context: .
136-
dockerfile_inline: |
137-
FROM base # image built for service base
138-
RUN ...
139-
additional_contexts:
140-
base: service:base
132+
base:
133+
build:
134+
context: .
135+
dockerfile_inline: |
136+
FROM alpine
137+
RUN ...
138+
my-service:
139+
build:
140+
context: .
141+
dockerfile_inline: |
142+
FROM base # image built for service base
143+
RUN ...
144+
additional_contexts:
145+
base: service:base
141146
```
142147

143148
### `args`
@@ -185,7 +190,6 @@ Compose Build implementations may support custom types, the Compose Specificatio
185190

186191
- `registry` to retrieve build cache from an OCI image set by key `ref`
187192

188-
189193
```yml
190194
build:
191195
context: .
@@ -205,8 +209,8 @@ Unsupported caches are ignored and don't prevent you from building images.
205209
build:
206210
context: .
207211
cache_to:
208-
- user/app:cache
209-
- type=local,dest=path/to/cache
212+
- user/app:cache
213+
- type=local,dest=path/to/cache
210214
```
211215

212216
Cache target is defined using the same `type=TYPE[,KEY=VALUE]` syntax defined by [`cache_from`](#cache_from).
@@ -232,7 +236,7 @@ services:
232236
build: https://github.com/mycompany/webapp.git
233237
```
234238

235-
If not set explicitly, `context` defaults to project directory (`.`).
239+
If not set explicitly, `context` defaults to project directory (`.`).
236240

237241
### `dockerfile`
238242

@@ -272,11 +276,11 @@ build:
272276

273277
`entitlements` defines extra privileged entitlements to be allowed during the build.
274278

275-
```yaml
276-
entitlements:
277-
- network.host
278-
- security.insecure
279-
```
279+
```yaml
280+
entitlements:
281+
- network.host
282+
- security.insecure
283+
```
280284

281285
### `extra_hosts`
282286

@@ -288,6 +292,7 @@ extra_hosts:
288292
- "otherhost=50.31.209.229"
289293
- "myhostv6=::1"
290294
```
295+
291296
IPv6 addresses can be enclosed in square brackets, for example:
292297

293298
```yml
@@ -349,7 +354,7 @@ Set the network containers connect to for the `RUN` instructions during build.
349354
build:
350355
context: .
351356
network: host
352-
```
357+
```
353358

354359
```yaml
355360
build:
@@ -390,6 +395,7 @@ When the `platforms` attribute is defined, Compose includes the service's
390395
platform, otherwise users won't be able to run images they built.
391396

392397
Composes reports an error in the following cases:
398+
393399
- When the list contains multiple platforms but the implementation is incapable of storing multi-platform images.
394400
- When the list contains an unsupported platform.
395401

@@ -400,6 +406,7 @@ Composes reports an error in the following cases:
400406
- "linux/amd64"
401407
- "unsupported/unsupported"
402408
```
409+
403410
- When the list is non-empty and does not contain the service's platform.
404411

405412
```yml
@@ -426,9 +433,9 @@ build:
426433

427434
### `provenance`
428435

429-
{{< summary-bar feature_name="Compose provenance" >}}
436+
{{< summary-bar feature_name="Compose provenance" >}}
430437

431-
`provenance` configures the builder to add a [provenance attestation](https://slsa.dev/provenance/v0.2#schema) to the published image.
438+
`provenance` configures the builder to add a [provenance attestation](https://slsa.dev/provenance/v0.2#schema) to the published image.
432439

433440
The value can be either a boolean to enable/disable provenance attestation, or a key=value string to set provenance configuration. You can
434441
use this to select the level of detail to be included in the provenance attestation by setting the `mode` parameter.
@@ -454,7 +461,7 @@ available in the local image store.
454461

455462
{{< summary-bar feature_name="Compose sbom" >}}
456463

457-
`sbom` configures the builder to add a [provenance attestation](https://slsa.dev/provenance/v0.2#schema) to the published image.
464+
`sbom` configures the builder to add a [provenance attestation](https://slsa.dev/provenance/v0.2#schema) to the published image.
458465
The value can be either a boolean to enable/disable sbom attestation, or a key=value string to set SBOM generator configuration. This let you
459466
select an alternative SBOM generator image (see https://github.com/moby/buildkit/blob/master/docs/attestations/sbom-protocol.md)
460467

@@ -551,23 +558,27 @@ Such grant must be explicit within service specification as [secrets](services.m
551558
`ssh` defines SSH authentications that the image builder should use during image build (e.g., cloning private repository).
552559

553560
`ssh` property syntax can be either:
554-
* `default`: Let the builder connect to the SSH-agent.
555-
* `ID=path`: A key/value definition of an ID and the associated path. It can be either a [PEM](https://en.wikipedia.org/wiki/Privacy-Enhanced_Mail) file, or path to ssh-agent socket.
561+
562+
- `default`: Let the builder connect to the SSH-agent.
563+
- `ID=path`: A key/value definition of an ID and the associated path. It can be either a [PEM](https://en.wikipedia.org/wiki/Privacy-Enhanced_Mail) file, or path to ssh-agent socket.
556564

557565
```yaml
558566
build:
559567
context: .
560568
ssh:
561-
- default # mount the default SSH agent
569+
- default # mount the default SSH agent
562570
```
571+
563572
or
573+
564574
```yaml
565575
build:
566576
context: .
567-
ssh: ["default"] # mount the default SSH agent
577+
ssh: ["default"] # mount the default SSH agent
568578
```
569579

570580
Using a custom id `myproject` with path to a local SSH key:
581+
571582
```yaml
572583
build:
573584
context: .
@@ -591,7 +602,7 @@ as an integer value representing the number of bytes or as a string expressing a
591602
```yml
592603
build:
593604
context: .
594-
shm_size: '2gb'
605+
shm_size: "2gb"
595606
```
596607

597608
```yaml

0 commit comments

Comments
 (0)