Skip to content

Commit e295a6e

Browse files
thaJeztahbermudezmt
authored andcommitted
Use site parameter to use latest compose file versions in examples (docker#8630)
* Use site parameter to use latest compose file versions in examples Make sure that examples use the latest version of the compose file format, to encourage using the latest version, and to prevent users from running into "not supported by this version" problems when copy/pasting, and combining examples that use different versions. Also add a note about `version: x` not being equivalent to `version: x.latest`. Note that there are still some examples using fixed versions in the UCP sections; we need to evaluate those to make sure the right (and supported) versions are used for UCP (which may be different than "latest"). Signed-off-by: Sebastiaan van Stijn <[email protected]> * Address some v3/v2 issues, and YAML syntax error Signed-off-by: Sebastiaan van Stijn <[email protected]> * Minor edit * Final updates - Added note around v2 and v3 versioning - Updated note for v3 to match the v2 update
1 parent 4616cfe commit e295a6e

File tree

5 files changed

+111
-73
lines changed

5 files changed

+111
-73
lines changed

_config.yml

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ latest_engine_api_version: "1.39"
2323
docker_ce_version: "18.09"
2424
docker_ee_version: "18.09"
2525
compose_version: "1.24.0"
26+
compose_file_v3: "3.7"
27+
compose_file_v2: "2.4"
2628
machine_version: "0.16.0"
2729
distribution_version: "2.6"
2830
dtr_version: "2.6"

_config_authoring.yml

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ latest_engine_api_version: "1.39"
2323
docker_ce_version: "18.09"
2424
docker_ee_version: "18.09"
2525
compose_version: "1.24.0"
26+
compose_file_v3: "3.7"
27+
compose_file_v2: "2.4"
2628
machine_version: "0.16.0"
2729
distribution_version: "2.6"
2830
dtr_version: "2.6"

compose/compose-file/compose-file-v2.md

+18-18
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ definition in version 2.
5050

5151
A set of configuration options to set block IO limits for this service.
5252

53-
version: '2.2'
53+
version: "{{ site.compose_file_v2 }}"
5454
services:
5555
foo:
5656
image: busybox
@@ -393,7 +393,7 @@ Express dependency between services, which has two effects:
393393

394394
Simple example:
395395

396-
version: '2'
396+
version: "{{ site.compose_file_v2 }}"
397397
services:
398398
web:
399399
build: .
@@ -418,7 +418,7 @@ the healthcheck) before starting.
418418

419419
Example:
420420

421-
version: '2.1'
421+
version: "{{ site.compose_file_v2 }}"
422422
services:
423423
web:
424424
build: .
@@ -667,7 +667,7 @@ details.
667667
A full example:
668668

669669
```
670-
version: '2'
670+
version: "{{ site.compose_file_v2 }}"
671671
services:
672672
myservice:
673673
image: alpine
@@ -741,14 +741,14 @@ Run an init inside the container that forwards signals and reaps processes.
741741
Either set a boolean value to use the default `init`, or specify a path to
742742
a custom one.
743743

744-
version: '2.2'
744+
version: "{{ site.compose_file_v2 }}"
745745
services:
746746
web:
747747
image: alpine:latest
748748
init: true
749749

750750

751-
version: '2.2'
751+
version: "{{ site.compose_file_v2 }}"
752752
services:
753753
web:
754754
image: alpine:latest
@@ -885,7 +885,7 @@ The general format is shown here.
885885

886886
In the example below, three services are provided (`web`, `worker`, and `db`), along with two networks (`new` and `legacy`). The `db` service is reachable at the hostname `db` or `database` on the `new` network, and at `db` or `mysql` on the `legacy` network.
887887

888-
version: '2'
888+
version: "{{ site.compose_file_v2 }}"
889889

890890
services:
891891
web:
@@ -920,7 +920,7 @@ The corresponding network configuration in the [top-level networks section](#net
920920

921921
An example:
922922

923-
version: '2.1'
923+
version: "{{ site.compose_file_v2 }}"
924924

925925
services:
926926
app:
@@ -954,7 +954,7 @@ managed by docker (IPAM driver).
954954

955955
Example usage:
956956

957-
version: '2.1'
957+
version: "{{ site.compose_file_v2 }}"
958958
services:
959959
app:
960960
image: busybox
@@ -977,7 +977,7 @@ In the following example, the `app` service connects to `app_net_1` first
977977
as it has the highest priority. It then connects to `app_net_3`, then
978978
`app_net_2`, which uses the default priority value of `0`.
979979

980-
version: '2.3'
980+
version: "{{ site.compose_file_v2 }}"
981981
services:
982982
app:
983983
image: busybox
@@ -1216,7 +1216,7 @@ expressed in the short form.
12161216

12171217

12181218
```none
1219-
version: "2.3"
1219+
version: "{{ site.compose_file_v2 }}"
12201220
services:
12211221
web:
12221222
image: nginx:alpine
@@ -1380,7 +1380,7 @@ Here's an example of a two-service setup where a database's data directory is
13801380
shared with another service as a volume so that it can be periodically backed
13811381
up:
13821382

1383-
version: "2.2"
1383+
version: "{{ site.compose_file_v2 }}"
13841384

13851385
services:
13861386
db:
@@ -1433,7 +1433,7 @@ In the example below, instead of attempting to create a volume called
14331433
`[projectname]_data`, Compose looks for an existing volume simply
14341434
called `data` and mount it into the `db` service's containers.
14351435

1436-
version: '2'
1436+
version: "{{ site.compose_file_v2 }}"
14371437

14381438
services:
14391439
db:
@@ -1484,14 +1484,14 @@ conflicting with those used by other software.
14841484
14851485
Set a custom name for this volume.
14861486

1487-
version: '2.1'
1487+
version: "{{ site.compose_file_v2 }}"
14881488
volumes:
14891489
data:
14901490
name: my-app-data
14911491

14921492
It can also be used in conjunction with the `external` property:
14931493

1494-
version: '2.1'
1494+
version: "{{ site.compose_file_v2 }}"
14951495
volumes:
14961496
data:
14971497
external: true
@@ -1609,7 +1609,7 @@ attempting to create a network called `[projectname]_outside`, Compose
16091609
looks for an existing network simply called `outside` and connect the `proxy`
16101610
service's containers to it.
16111611

1612-
version: '2'
1612+
version: "{{ site.compose_file_v2 }}"
16131613

16141614
services:
16151615
proxy:
@@ -1644,14 +1644,14 @@ Not supported for version 2 `docker-compose` files. Use
16441644
16451645
Set a custom name for this network.
16461646

1647-
version: '2.1'
1647+
version: "{{ site.compose_file_v2 }}"
16481648
networks:
16491649
network1:
16501650
name: my-app-net
16511651

16521652
It can also be used in conjunction with the `external` property:
16531653

1654-
version: '2.1'
1654+
version: "{{ site.compose_file_v2 }}"
16551655
networks:
16561656
network1:
16571657
external: true

compose/compose-file/compose-versioning.md

+41-5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ omitting a `version` key at the root of the YAML.
5252
be cross-compatible between Compose and the Docker Engine's
5353
[swarm mode](/engine/swarm/index.md). This is specified with a `version: '3'` or `version: '3.1'`, etc., entry at the root of the YAML.
5454

55+
> ### v2 and v3 Declaration
56+
>
57+
> **Note**: When specifying the Compose file version to use, make sure to
58+
> specify both the _major_ and _minor_ numbers. If no minor version is given,
59+
> `0` is used by default and not the latest minor version.
60+
5561

5662
The [Compatibility Matrix](#compatibility-matrix) shows Compose file versions mapped to Docker Engine releases.
5763

@@ -121,9 +127,24 @@ discoverable at a hostname that's the same as the service name. This means
121127
[links](compose-file-v2.md#links) are largely unnecessary. For more details, see
122128
[Networking in Compose](compose-file-v2.md#networking.md).
123129

130+
> **Note**: When specifying the Compose file version to use, make sure to
131+
> specify both the _major_ and _minor_ numbers. If no minor version is given,
132+
> `0` is used by default and not the latest minor version. As a result, features added in
133+
> later versions will not be supported. For example:
134+
>
135+
> ```yaml
136+
> version: "2"
137+
> ```
138+
>
139+
> is equivalent to:
140+
>
141+
> ```yaml
142+
> version: "2.0"
143+
> ```
144+
124145
Simple example:
125146
126-
version: '2'
147+
version: "{{ site.compose_file_v2 }}"
127148
services:
128149
web:
129150
build: .
@@ -136,7 +157,7 @@ Simple example:
136157
137158
A more extended example, defining volumes and networks:
138159
139-
version: '2'
160+
version: "{{ site.compose_file_v2 }}"
140161
services:
141162
web:
142163
build: .
@@ -169,7 +190,7 @@ Several other options were added to support networking, such as:
169190
* The [`depends_on`](compose-file-v2.md#depends_on) option can be used in place of links to indicate dependencies
170191
between services and startup order.
171192
172-
version: '2'
193+
version: "{{ site.compose_file_v2 }}"
173194
services:
174195
web:
175196
build: .
@@ -259,6 +280,21 @@ the [upgrading](#upgrading) guide for how to migrate away from these.
259280
260281
- Added: [deploy](/compose/compose-file/index.md#deploy)
261282
283+
> **Note**: When specifying the Compose file version to use, make sure to
284+
> specify both the _major_ and _minor_ numbers. If no minor version is given,
285+
> `0` is used by default and not the latest minor version. As a result, features added in
286+
> later versions will not be supported. For example:
287+
>
288+
> ```yaml
289+
> version: "3"
290+
> ```
291+
>
292+
> is equivalent to:
293+
>
294+
> ```yaml
295+
> version: "3.0"
296+
> ```
297+
262298
### Version 3.3
263299
264300
An upgrade of [version 3](#version-3) that introduces new parameters only
@@ -327,7 +363,7 @@ several options have been removed:
327363
[top-level `volumes` option](/compose/compose-file/index.md#volume-configuration-reference)
328364
and specify the driver there.
329365
330-
version: "3"
366+
version: "{{ site.compose_file_v3 }}"
331367
services:
332368
db:
333369
image: postgres
@@ -422,7 +458,7 @@ It's more complicated if you're using particular configuration features:
422458
named volume called `data`, you must declare a `data` volume in your
423459
top-level `volumes` section. The whole file might look like this:
424460
425-
version: '2'
461+
version: "{{ site.compose_file_v2 }}"
426462
services:
427463
db:
428464
image: postgres

0 commit comments

Comments
 (0)