Closed ben-page closed 1 year ago
command
is another array that could benefit from merging.
If I look at the documentation here, it says:
For single-value options like image, command or mem_limit, the new value replaces the old value.
However the doc about command
here says the inverse:
The command can also be a list, in a manner similar to dockerfile.
For me this is a pretty useful scenario where I would extend the list of commands for a container via compose file merging, but there is no easy way to do this. Please let me know if this deserves a separate issue.
command
is another array that could benefit from merging.If I look at the documentation here, it says:
For single-value options like image, command or mem_limit, the new value replaces the old value.
However the doc about
command
here says the inverse:The command can also be a list, in a manner similar to dockerfile.
For me this is a pretty useful scenario where I would extend the list of commands for a container via compose file merging, but there is no easy way to do this. Please let me know if this deserves a separate issue.
I'm just trying to merge command
via compose.override.yaml
for a Traefik container on a system where I need an additional config like this:
services:
traefik:
command:
- --providers.file.filename=/etc/traefik/rules.yaml
volumes:
- ${PWD}/rules.yaml:/etc/traefik/rules.yaml:ro
extra_hosts:
- host.docker.internal:host-gateway
Turns out it doesn't work because command
in compose.override.yaml
just overwrites compose.yaml
.
Shell commands ALWAYS are overridden, see https://github.com/compose-spec/compose-spec/blob/master/13-merge.md#shell-commands
Your use case is better addressed with an entrypoint + command to pass additional parameters
https://docs.docker.com/compose/multiple-compose-files/merge/#merging-rules
For single-value options like image, command or mem_limit, the new value replaces the old value.
I'm not a YAML expert, but
command:
- --argument1
- --argument2
- --argument3
looks like a sequence/list to me.
better read the reference : https://docs.docker.com/compose/multiple-compose-files/merge/#reference-information
The reason a command in sequence form isn't treated like other sequences is that it's internally converted to exec syntax then I guess, wouldn't it make sense to explicity mention that?
as already noted, this is explicitly documented in reference content https://github.com/compose-spec/compose-spec/blob/master/13-merge.md#shell-commands
It may technically by explicit but not clear as it's conflicting with the sequence merge logic.
Description
docker compose
doesn't properly merge arrays. This can lead to an invalid docker compose file being generated. And it's a breaking change between v1 and v2.Steps to reproduce the issue:
a.yml
b.yml
Describe the results you received:
docker compose
generated an invalid docker compose file.exposes
is expected to contain unique values and will error out.healthcheck.test
is valid, but messed up.Describe the results you expected:
Additional information you deem important (e.g. issue happens only occasionally):
Docker Compose v1 worked differently:
The behavior of
docker-compose
(v1) isn't completely obvious. It appears to use different strategies for different arrays. It seems to be mergingexposes
and removing duplicates, but overwritingheathchecks.test
.For example,
a.yml
b.yml
Returns:
Output of
docker compose version
:Output of
docker info
:Additional environment details: