---
title: Merge
description: Learn about merging rules
keywords: compose, compose specification, merge, compose file reference
aliases:
- /compose/compose-file/13-merge/
weight: 100
---
{{% include "compose/merge.md" %}}
These rules are outlined below.
## Mapping
A YAML `mapping` gets merged by adding missing entries and merging the conflicting ones.
Merging the following example YAML trees:
```yaml
services:
foo:
key1: value1
key2: value2
```
```yaml
services:
foo:
key2: VALUE
key3: value3
```
Results in a Compose application model equivalent to the YAML tree:
```yaml
services:
foo:
key1: value1
key2: VALUE
key3: value3
```
## Sequence
A YAML `sequence` is merged by appending values from the overriding Compose file to the previous one.
Merging the following example YAML trees:
```yaml
services:
foo:
DNS:
- 1.1.1.1
```
```yaml
services:
foo:
DNS:
- 8.8.8.8
```
Results in a Compose application model equivalent to the YAML tree:
```yaml
services:
foo:
DNS:
- 1.1.1.1
- 8.8.8.8
```
## Exceptions
### Shell commands
When merging Compose files that use the services attributes [command](services.md#command), [entrypoint](services.md#entrypoint) and [healthcheck: `test`](services.md#healthcheck), the value is overridden by the latest Compose file, and not appended.
Merging the following example YAML trees:
```yaml
services:
foo:
command: ["echo", "foo"]
```
```yaml
services:
foo:
command: ["echo", "bar"]
```
Results in a Compose application model equivalent to the YAML tree:
```yaml
services:
foo:
command: ["echo", "bar"]
```
### Unique resources
Applies to the [ports](services.md#ports), [volumes](services.md#volumes), [secrets](services.md#secrets) and [configs](services.md#configs) services attributes.
While these types are modeled in a Compose file as a sequence, they have special uniqueness requirements:
| Attribute | Unique key |
|-------------|--------------------------|
| volumes | target |
| secrets | target |
| configs | target |
| ports | {ip, target, published, protocol} |
When merging Compose files, Compose appends new entries that do not violate a uniqueness constraint and merge entries that share a unique key.
Merging the following example YAML trees: