Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] mapping key "<<" already defined in version >=2.17.0 #10407

Closed
frederikhs opened this issue Mar 27, 2023 · 1 comment
Closed

[BUG] mapping key "<<" already defined in version >=2.17.0 #10407

frederikhs opened this issue Mar 27, 2023 · 1 comment

Comments

@frederikhs
Copy link

Description

Upon upgrading from Docker Compose version 2.16.0 to Docker Compose version 2.17.2 it seems like 2.17 and above dropped support for merging in yaml, ref: https://yaml.org/type/merge.html

yaml: unmarshal errors:
  line 155: mapping key "<<" already defined at line 154
  line 192: mapping key "<<" already defined at line 191

I seems to happen when to merge keys << exists in the same service. If only 1 exist there is not error.

I see nowhere this is mentioned. I will therefore make this issue a bug since it is.

Steps To Reproduce

Using the follow docker compose file:

x-environment: &env
  environment:
    SOME_VARIABLE: "some_value"

x-deploy-limit: &deploy-limit
  deploy:
    resources:
      limits:
        memory: 24M

services:
  service_a:
    image: alpine
    command: [ "sleep", "infinity"]
    <<: *env
    <<: *deploy-limit

Running:

docker compose config

Results in:

yaml: unmarshal errors:
  line 16: mapping key "<<" already defined at line 15

Compose Version

$ docker compose version
Docker Compose version 2.17.2
$ docker-compose version
Docker Compose version 2.17.2

Docker Environment

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  0.10.4
    Path:     /usr/lib/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  2.17.2
    Path:     /usr/lib/docker/cli-plugins/docker-compose

Server:
 Containers: 17
  Running: 17
  Paused: 0
  Stopped: 0
 Images: 42
 Server Version: 23.0.1
 Storage Driver: btrfs
  Btrfs:
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 1fbd70374134b891f97ce19c70b6e50c7b9f4e0d.m
 runc version:
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.2.8-arch1-1
 Operating System: Arch Linux
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 31.08GiB
 Name: g9
 ID: YW5O:Q2E6:YWE4:K65D:PTOH:TAYN:AGI6:LEYU:I2NH:B3UQ:CRQH:PZFG
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Anything else?

No response

@laurazard
Copy link
Member

Hiya @frederikhs, thanks for the report.

Check #10394, particularly #10394 (comment):

YAML parsing was improved in v2.17 - the old behavior of allowing multiple merge keys was a quirk of the parser.

However, as @jorgenader mentioned, you can provide multiple anchors in a single merge key.

This is the expected pattern as documented at https://yaml.org/type/merge.html.

You should address this by providing both anchors in the single merge key, such as:

x-environment: &env
  environment:
    SOME_VARIABLE: "some_value"

x-deploy-limit: &deploy-limit
  deploy:
    resources:
      limits:
        memory: 24M

services:
  service_a:
    image: alpine
    command: [ "sleep", "infinity"]
    <<: [*env, *deploy-limit]

@laurazard laurazard closed this as not planned Won't fix, can't repro, duplicate, stale Mar 27, 2023
Vadman97 pushed a commit to highlight/highlight that referenced this issue Mar 31, 2023
## Summary

Currently fails to deploy with the docker compose file on versions
greater than v2.17, see
[this](docker/compose#10407 (comment))
mralexandernickel added a commit to flagbit/packeton that referenced this issue Apr 24, 2023
gopherbot pushed a commit to golang/pkgsite that referenced this issue May 19, 2023
Current content.yaml format errors with docker-compose v2.17+. Running snapshot tests currently errors with:

unmarshal errors:
  line 37: mapping key “<<” already defined at line 36
  line 52: mapping key “<<” already defined at line 51
  line 83: mapping key “<<” already defined at line 82

This CR fixes that error.

Context:
docker/compose#10407 (comment)

Change-Id: I15d9e1d7bb799819a783904cf9dc0bb5a26efcae
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/496189
Run-TryBot: Jamal Carvalho <jamal@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
robomics added a commit to robomics/conan-docker-tools that referenced this issue May 27, 2023
Fix a bunch of `mapping key "<<" already defined in version` errors when
building images using docker compose v2.17+.

See:
- docker/compose#10407
- docker/compose#10394 (comment)
mathbou pushed a commit to mathbou/docker-cgwire that referenced this issue Jun 3, 2023
mathbou pushed a commit to mathbou/docker-cgwire that referenced this issue Jun 3, 2023
ianpinder pushed a commit to ianpinder/docker-kitsu-ngrok that referenced this issue Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants