docker / docker/compose

[BUG] !reset tag does not work on environment keys when multiple files contibute

Open
#11,816 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

kind/bug
Dominant language
Go
Stars
38.2k
Forks
5.8k
Avg merge
2d 14h
Merged PRs (30d)
55

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the merge with test1.yml, test2.yml, and override.yml using docker compose ... config, then inspect the Compose merge handling for environment mappings and !reset. Add a regression test covering values contributed by multiple files and verify the generated configuration removes both environment keys as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker-compose, go
Domain
devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.