Repository navigation
Description
Description
When using multiple compose files with the -f option, each can define amendments to a service defined in a previous file. When the first two files define environment variables for a service, subsequent files are unable to use the !reset tag to remove these environment key value pairs, per the example at https://docs.docker.com/compose/compose-file/13-merge/#reset-value. If only one file defines environment key value pairs then another is able to reset them as expected.
This probably applies to other parts of the service definition but only the environment key was tested.
Steps To Reproduce
With the following files:
test1.yml
services:
app:
image: myapp
ports:
- "8080:80"
environment:
FOO: BAR
test2.yml
services:
app:
environment:
ANOTHER: BAR
override.yml
services:
app:
image: myapp
ports: !reset []
environment:
ANOTHER: !reset null
FOO: !reset null
Run
docker compose -f test1.yml -f test2.yml -f override.yml config
Resulting in: (directory run in was named tests)
name: tests
services:
app:
environment:
ANOTHER: BAR
FOO: BAR
image: myapp
networks:
default: null
networks:
default:
name: tests_default
Expected result would be:
name: tests
services:
app:
image: myapp
networks:
default: null
networks:
default:
name: tests_default
Compose Version
Docker Compose version v2.27.0
Docker Environment
Client: Docker Engine - Community
Version: 26.1.2
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc.)
Version: v0.14.0
Path: /usr/libexec/docker/cli-plugins/docker-buildx
compose: Docker Compose (Docker Inc.)
Version: v2.27.0
Path: /usr/libexec/docker/cli-plugins/docker-compose
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 599
Server Version: 26.1.2
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Using metacopy: false
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 runc
Default Runtime: runc
Init Binary: docker-init
containerd version: e377cd56a71523140ca6ae87e30244719194a521
runc version: v1.1.12-0-g51d5e94
init version: de40ad0
Security Options:
apparmor
seccomp
Profile: builtin
Kernel Version: 5.15.0-88-generic
Operating System: Ubuntu 20.04.6 LTS
OSType: linux
Architecture: x86_64
CPUs: 16
Total Memory: 15.39GiB
Name: antigluon
ID: NA5I:MFNI:AKAR:M2X3:LA3S:Y5B3:4NE2:4WAH:2GFN:PHFF:O7MS:JYUQ
Docker Root Dir: /var/lib/docker
Debug Mode: false
Experimental: false
Insecure Registries:
gamma.si:5100
127.0.0.0/8
Live Restore Enabled: false
Anything else?
No response
Activity
mattsouthern commentedon May 15, 2024
Additionally would be nice if combining
!resetand yaml anchors like the following worked:file1.yml
override.yml
current output of
docker compose -f file1.yml -f override.yml config(!resettag not respected):ndeloof commentedon May 15, 2024
environmentis managed internally using theKEY=VALUErepresentation during the merge phase, this is why!resetdoesn't work here. Not sure how this could be fixed...anchor is a yaml syntax fature, applied by the low level yaml parser. This takes place before we merge yaml files together, so this is not possible
hablutzel1 commentedon Dec 17, 2025
Then the documentation at https://docs.docker.com/reference/compose-file/merge/#reset-value is wrong, no?
ndeloof commentedon Dec 17, 2025
Had to re-read the original issue description, there's actually something weird as 3 yaml files get merged, the last one using
!reset. If I only use 2 of those the documented behavior applies. Let me investigatendeloof commentedon Dec 17, 2025
My initial diagnostic was right: during yaml merge process,
envrionmentis converted to use the KEY=VALUE syntax (this is the only way we can merge even without interpolation). So aftertest1.ymlhas been merged withtest2.yml, the list syntax disables ability to apply!resetas theservices.app.environment.FOOyaml path never matches a node.I don't think there's any simple way to fix this with the compose-go architecture
hablutzel1 commentedon Dec 17, 2025
@ndeloof , thanks for checking. It would be nice to have the documentation updated.
ndeloof commentedon Dec 17, 2025
@hablutzel1 this is a bug, not to be documented but fixed, while I'm not sure "how" yet
hablutzel1 commentedon Dec 17, 2025
That's even better ;)
github-actions commentedon May 17, 2026
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
oskolist commentedon May 17, 2026
any update? (to prevent github-action bot to lock this issue)
stale commentedon May 17, 2026
This issue has been automatically marked as not stale anymore due to the recent activity.
loader: honor !reset on keys of fields normalized into KEY=VALUE sequ…
loader: honor !reset on keys of fields normalized into KEY=VALUE sequ…