<p>According <a href="https://docs.docker.com/compose/reference/overview/#specifying-multiple-compose-files" rel="noreferrer">to this documentation</a> it does not seem to be possible to override complete sections in docker-compose by using different docker-compose files.</p>

<blockquote>
  <p>If both files are present on the same directory level, Compose
  combines the two files into a single configuration.</p>
  
  <p>The configuration in the docker-compose.override.yml file is applied
  over and in addition to the values in the docker-compose.yml file.</p>
</blockquote>

CC BY-SA 3.0
2017-10-03T11:40:00.433Z
2017-10-03T11:40:00.433Z
030
<p>The docker-compose.override contains:</p>

<pre><code>volumes:
  - ./a:/path/to/a
</code></pre>

<p>The docker-compose:</p>

<pre><code>volumes:
  - a:/path/to/a
</code></pre>

<p>When docker-compose up is run the override overwrite the <code>./a</code> overwrites the <code>a</code>.</p>

<p>When a new volume is added to docker-compose, the override will try to mount is as well. </p>

<p>docker-compose.override</p>

<pre><code>volumes:
  - ./a:/path/to/a
</code></pre>

<p>The docker-compose:</p>

<pre><code>volumes:
  - a:/path/to/a
  - b:/path/to/b
</code></pre>

<p>How to prevent that the override will use volumes that are defined in the docker-compose file?</p>

<p>When docker-compose.override contains</p>

<pre><code>volumes:
  - a:/path/to/a
  - .b:/path/to/b
</code></pre>

<p>the b is still mounted...</p>

<docker-compose>
What are best practices to override complete sections using docker-compose?
030
# What are best practices to override complete sections using docker-compose?

(Asked by: username_0 on 2017-06-06)

The docker-compose.override contains:
volumes:
  - ./a:/path/to/a

The docker-compose:
volumes:
  - a:/path/to/a

When docker-compose up is run the override overwrite the ./a overwrites the a.
When a new volume is added to docker-compose, the override will try to mount is as well. 
docker-compose.override
volumes:
  - ./a:/path/to/a

The docker-compose:
volumes:
  - a:/path/to/a
  - b:/path/to/b

How to prevent that the override will use volumes that are defined in the docker-compose file?
When docker-compose.override contains
volumes:
  - a:/path/to/a
  - .b:/path/to/b

the b is still mounted...

**Tags:** docker-compose


---

## 1 answers

### Answer by username_0 on 2017-10-03. Score: 5 | Accepted answer

According [to this documentation](https://docs.docker.com/compose/reference/overview/#specifying-multiple-compose-files) it does not seem to be possible to override complete sections in docker-compose by using different docker-compose files.

> If both files are present on the same directory level, Compose
> combines the two files into a single configuration.
>
> The configuration in the docker-compose.override.yml file is applied
> over and in addition to the values in the docker-compose.yml file.


---

