Search code examples
dockerdocker-swarm

Docker: remove a setting when using multiple YAML files


Using Docker Swarm, I keep all my "overrides" in a single yml file like so:

docker stack -c base.yml -c overrides.yml deploy myStack

If my base.yml file defines these deploy limits for serviceA:

serviceA:
  . . .
  deploy:
    resources:
      limits: {memory: 1024M}
      reservations: {memory: 1024M}

I can easily override in overrides.yml:

serviceA:
  deploy:
    resources:
      limits: {memory: 2048M}
      reservations: {memory: 2048M}

This way, my base.yml can change as new versions of the product are released, but any overrides are easily transported from the old to the new version. However, what if I want to REMOVE or delete something defined in base.yml? If I want to keep the reservation, but remove the limits definition by using a second yml file. Is there any way to do this? Currently, I am on yaml version 3.6.

These two options do not work. This (is not parseable):

serviceA:
  deploy:
    resources:
      limits: {memory: }
      reservations: {memory: 2048M}

and this (uses the default defined in base.yml):

serviceA:
  deploy:
    resources:
      reservations: {memory: 2048M}

Solution

  • When using multiple docker-compose files, the latter ones get merged into the former ones. That means: You cannot remove definitions, just modify existing ones or add new ones (see https://github.com/docker/compose/issues/3729). A PR to allow that was created and closed without ever being merged.

    So all that leaves you with is to remove the limits definition from your base.yml and only have it in your overrides.yml.