mirror of https://github.com/docker/docs.git
ENGDOCS-1993 (#19441)
* ENGDOCS-1993 * improve reset and override example
This commit is contained in:
parent
6f85349dd1
commit
6d32e6e940
|
@ -1151,7 +1151,7 @@ There is a performance penalty for applications that swap memory to disk often.
|
|||
|
||||
- `none`: Turns off all container networking.
|
||||
- `host`: Gives the container raw access to the host's network interface.
|
||||
- `service:{name}`: Gives the containers access to the specified service only.
|
||||
- `service:{name}`: Gives the containers access to the specified service only. For more information, see [Container networks](../../network/_index.md#container-networks).
|
||||
|
||||
```yml
|
||||
network_mode: "host"
|
||||
|
|
|
@ -145,41 +145,35 @@ For readability, it is recommended to explicitly set the attribute value to the
|
|||
array `[]` (with `!reset null` or `!reset []`) so that it is clear that resulting attribute will be
|
||||
cleared.
|
||||
|
||||
Merging the following example YAML trees:
|
||||
A base `compose.yaml` file:
|
||||
|
||||
```yaml
|
||||
services:
|
||||
foo:
|
||||
build:
|
||||
dockerfile: foo.Dockerfile
|
||||
read_only: true
|
||||
environment:
|
||||
FOO: BAR
|
||||
app:
|
||||
image: myapp
|
||||
ports:
|
||||
- "8080:80"
|
||||
- "8080:80"
|
||||
environment:
|
||||
FOO: BAR
|
||||
```
|
||||
|
||||
And an `overide.compose.yaml` file:
|
||||
|
||||
```yaml
|
||||
services:
|
||||
foo:
|
||||
image: foo
|
||||
build: !reset null
|
||||
read_only: !reset false
|
||||
app:
|
||||
image: myapp
|
||||
ports: !reset []
|
||||
environment:
|
||||
FOO: !reset null
|
||||
ports: !reset []
|
||||
```
|
||||
|
||||
Result in a Compose application model equivalent to the YAML tree:
|
||||
Results in:
|
||||
|
||||
```yaml
|
||||
services:
|
||||
foo:
|
||||
image: foo
|
||||
build: null
|
||||
read_only: false
|
||||
environment: {}
|
||||
ports: []
|
||||
app:
|
||||
image: myapp
|
||||
```
|
||||
|
||||
### Replace value
|
||||
|
@ -189,24 +183,36 @@ services:
|
|||
While `!reset` can be used to remove a declaration from a Compose file using an override file, `!override` allows you
|
||||
to fully replace an attribute, bypassing the standard merge rules. A typical example is to fully replace a resource definition, to rely on a distinct model but using the same name.
|
||||
|
||||
Merging the following example YAML trees:
|
||||
A base `compose.yaml` file:
|
||||
|
||||
```yaml
|
||||
networks:
|
||||
foo:
|
||||
# this is production configuration
|
||||
name: production-overlay-network
|
||||
driver: overlay
|
||||
driver-opts: (...)
|
||||
services:
|
||||
app:
|
||||
image: myapp
|
||||
ports:
|
||||
- "8080:80"
|
||||
```
|
||||
|
||||
To remove the original port, but expose a new one, the following override file is used:
|
||||
|
||||
```yaml
|
||||
networks:
|
||||
# this is development configuration
|
||||
foo: !override {}
|
||||
services:
|
||||
app:
|
||||
ports: !override
|
||||
- "8443:443"
|
||||
```
|
||||
|
||||
Results in a Compose application model equivalent to the override YAML tree.
|
||||
This results in:
|
||||
|
||||
```yaml
|
||||
services:
|
||||
app:
|
||||
image: myapp
|
||||
ports:
|
||||
- "8443:443"
|
||||
```
|
||||
|
||||
If `!override` had not been used, both `8080:80` and `8443:443` would be exposed as per the [merging rules outlined above](#sequence).
|
||||
|
||||
## Additional resources
|
||||
|
||||
|
|
Loading…
Reference in New Issue