mirror of
https://github.com/docker/docs.git
synced 2026-03-27 14:28:47 +07:00
extends and build patch (#20272)
This commit is contained in:
@@ -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`
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user