extends and build patch (#20272)

This commit is contained in:
Allie Sadler
2024-06-25 08:23:09 +01:00
committed by GitHub
parent 069a0810ef
commit 512671276e
2 changed files with 3 additions and 45 deletions

View File

@@ -8,10 +8,10 @@ keywords: compose, compose specification, compose file reference, compose build
In the former case, the whole path is used as a Docker context to execute a Docker build, looking for a canonical
`Dockerfile` at the root of the directory. The path can be absolute or relative. If it is relative, it is resolved
from the Compose file's parent folder. If it is absolute, the path prevents the Compose file from being portable so Compose displays a warning.
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.
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
from the Compose file's parent folder. If it is absolute, the path prevents the Compose file from being portable so Compose displays a warning.
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.
## Using `build` and `image`

View File

@@ -112,9 +112,7 @@ services:
cpu_shares: 10
```
## Further examples
### Example one
## Additional example
Extending an individual service is useful when you have multiple services that
have a common configuration. The example below is a Compose app with two
@@ -158,46 +156,6 @@ services:
- queue
```
### Example two
Another common use case for `extends` is running one off or administrative tasks
against one or more services in a Compose app. This example demonstrates running
a database backup.
The `docker-compose.yml` defines the base configuration.
```yaml
services:
web:
image: example/my_web_app:latest
depends_on:
- db
db:
image: postgres:latest
```
`docker-compose.admin.yml` adds a new service to run the database export or
backup.
```yaml
services:
dbadmin:
build: database_admin/
depends_on:
- db
```
To start a normal environment, run `docker compose up -d`. To run a database
backup, include the `docker-compose.admin.yml` as well.
```console
$ docker compose -f docker-compose.yml -f docker-compose.admin.yml \
run dbadmin db-backup
```
Compose extends files in the order they're specified on the command line.
## Exceptions and limitations
`volumes_from` and `depends_on` are never shared between services using