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] using multiple yaml alias not working. mapping key "<<" already defined #10411

Closed
arulrajnet opened this issue Mar 29, 2023 · 7 comments
Closed
Assignees
Labels

Comments

@arulrajnet
Copy link

Description

docker-compose.yml

version: '3.9'

# yml aliases and anchors
x-mysql: &mysqlenv
  MYSQL_ROOT_PASSWORD: root
  MYSQL_DATABASE: test
  MYSQL_USER: test
  MYSQL_PASSWORD: test

x-mysql-extraenv: &mysqlextraenv
  MY_CUSTOM_VAR: mycustomvalue

services:
  mysql:
    image: mysql:5.7
    environment:
      <<: *mysqlenv
      <<: *mysqlextraenv
    volumes:
      - mysql-data:/var/lib/mysql

volumes:
  mysql-data:

Try docker-compose config. Then getting the following error

yaml: unmarshal errors:
  line 18: mapping key "<<" already defined at line 17

The version of my docker-compose is 2.17.2

The same is working in 2.15.1 , 2.16.0 and even release candidate version 2.17.0-rc.1.

This is broken from version 2.17.0

2023-03-29_09-13

Steps To Reproduce

  1. Windows 11
  2. Docker compose v2.17.0
  3. Copy the above docker-compose.yml
  4. Then docker-compose config
  5. You will see the error

Compose Version

Docker Compose version v2.17.0

Docker Environment

Client:
 Context:    default
 Debug Mode: false

Server:
 Containers: 9
  Running: 1
  Paused: 0
  Stopped: 8
 Images: 53
 Server Version: 23.0.0
 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: 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: 31aa4358a36870b21a992d3ad2bef29e1d693bec
 runc version: v1.1.4-0-g5fd4c4d
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 5.15.0-67-generic
 Operating System: Ubuntu 22.04 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 8.736GiB
 Name: ubuntuserver2204
 ID: c8839b3e-9c74-4cb6-9444-e5c979394be0
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Username: arulrajnet
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: API is accessible on http://0.0.0.0:2375 without encryption.
         Access to the remote API is equivalent to root access on the host. Refer
         to the 'Docker daemon attack surface' section in the documentation for
         more information: https://docs.docker.com/go/attack-surface/

Anything else?

Not Working in 2.17.0

arul@windows ~/Downloads/dc-yaml-alias-bug$~/Downloads/docker-compose-windows-x86_64-2.17.0.exe config
yaml: unmarshal errors:
  line 18: mapping key "<<" already defined at line 17

Working in 2.17.0-rc.1

arul@windows ~/Downloads/dc-yaml-alias-bug$~/Downloads/docker-compose-windows-x86_64-2.17.0-rc.1.exe config
name: dc-yaml-alias-bug
services:
  mysql:
    environment:
      MY_CUSTOM_VAR: mycustomvalue
      MYSQL_DATABASE: test
      MYSQL_PASSWORD: test
      MYSQL_ROOT_PASSWORD: root
      MYSQL_USER: test
    image: mysql:5.7
    networks:
      default: null
    volumes:
    - type: volume
      source: mysql-data
      target: /var/lib/mysql
      volume: {}
networks:
  default:
    name: dc-yaml-alias-bug_default
volumes:
  mysql-data:
    name: dc-yaml-alias-bug_mysql-data
x-mysql:
  MYSQL_DATABASE: test
  MYSQL_PASSWORD: test
  MYSQL_ROOT_PASSWORD: root
  MYSQL_USER: test
x-mysql-extraenv:
  MY_CUSTOM_VAR: mycustomvalue
@ndeloof
Copy link
Contributor

ndeloof commented Mar 29, 2023

Thanks for reporting this issue, I'll look into this today

@ndeloof
Copy link
Contributor

ndeloof commented Mar 29, 2023

This is an unexpected side-effect upgrading to go-yaml/v3

@ndeloof
Copy link
Contributor

ndeloof commented Mar 29, 2023

goyaml/v3 does not support repeated anchors (due to internal storage using << as key during parsing) but allows use of multi-values in anchors

    environment:
      <<:  [*mysqlenv, *mysqlextraenv]

According to https://yaml.org/type/merge.html this is the expected syntax

@arulrajnet
Copy link
Author

Thanks, @ndeloof. This fix works. Will close this.

@gowrizrh
Copy link

One thing to note that it's not quite the same behaviour.

Value overrides don't work as before. If you previously had

x-mysql: &mysqlenv
  MYSQL_USER: test

x-mysql-extraenv: &mysqlextraenv
  MYSQL_USER: overridetest

    environment:
      <<: *mysqlenv
      <<: *mysqlextraenv

the value of the variable MYSQL_USER would have been overriden to the overridetest.

However with the new syntax, the value for MYSQL_USER is test.

    environment:
      <<: [*mysqlenv, *mysqlextraenv]

@gowrizrh
Copy link

gowrizrh commented Mar 30, 2023

Sorry for the noise, but it seems to merge in reverse?

Rewriting it as

    environment:
      <<: [*mysqlextraenv, *mysqlenv]

Does override values of mysqlenv with values from mysqlextraenv

@gowrizrh
Copy link

Ok, after swifting through https://yaml.org/type/merge.html it does mention this.

If the value associated with the merge key is a sequence, then this sequence is expected to contain mapping nodes and each of these nodes is merged in turn according to its order in the sequence. Keys in mapping nodes earlier in the sequence override keys specified in later mapping nodes.

I hope it's helpful to someone else.

mmguero added a commit to idaholab/Malcolm that referenced this issue Apr 5, 2023
Malcolm v23.04.0 is a release with enhancements, component version updates and bug fixes.

IMPORTANT NOTE: In March 2023 Docker Inc. announced its decision to sunset the "Docker Free Team" plan, which prompted us to decide to migrate away from Docker Hub to the Github Container Registry or "ghcr" (see #163). Due to public backlash, Docker Inc. reversed its decision. However, the Malcolm project will continue with the decision to use GHCR beginning with this release (Malcolm v23.04.0) and moving forward. If you're updating an existing instance of Malcolm, it's recommended that you back up your `docker-compose.yml` and `docker-compose-standalone.yml` files, replace them with the ones from this release and re-run `./scripts/install.py --configure` to ensure that you're pointing at the latest images (this is actually always good practice when moving to a new release of Malcolm).

v23.03.0...v23.04.0

* Enhancements
    - autostart `install.py --configure` on Malcolm ISO first boot (#157)
    - clarify information about auth_setup's use of external OpenSearch connections (#160)
    - migrate away from DockerHub container registry (#163)
    - give easier option for transferring SSL client files from Malcolm to forwarder (#177)
        + added `tx-rx-secure.sh` script as wrapper around [croc](https://github.com/schollz/croc) automatically creating and using a local-only relay

* Component version updates
    - [Zeek v5.2.0](https://github.com/zeek/zeek/releases) (#161)
    - [fluent bit v2.0.10](https://fluentbit.io/announcements/v2.0.10/)
    - [NetBox v3.4.7](https://github.com/netbox-community/netbox/releases/tag/v3.4.7)

* Fixes
    - XFCE4's "save session on exit" causes conflict with Hedgehog kiosk mode if firefox instance is started upon session restore (#164)
    - docker-compose move from go-yaml/v3 breaks Malcolm's docker-compose YAML files (#178, docker/compose#10411)
    - increase index.mapping.nested_fields.limit in opensearch index template (#180)
mmguero added a commit to cisagov/Malcolm that referenced this issue Apr 5, 2023
Malcolm v23.04.0 is a release with enhancements, component version updates and bug fixes.

IMPORTANT NOTE: In March 2023 Docker Inc. announced its decision to sunset the "Docker Free Team" plan, which prompted us to decide to migrate away from Docker Hub to the Github Container Registry or "ghcr" (see idaholab#163). Due to public backlash, Docker Inc. reversed its decision. However, the Malcolm project will continue with the decision to use GHCR beginning with this release (Malcolm v23.04.0) and moving forward. If you're updating an existing instance of Malcolm, it's recommended that you back up your `docker-compose.yml` and `docker-compose-standalone.yml` files, replace them with the ones from this release and re-run `./scripts/install.py --configure` to ensure that you're pointing at the latest images (this is actually always good practice when moving to a new release of Malcolm).

v23.03.0...v23.04.0

* Enhancements
    - autostart `install.py --configure` on Malcolm ISO first boot (idaholab#157)
    - clarify information about auth_setup's use of external OpenSearch connections (idaholab#160)
    - migrate away from DockerHub container registry (idaholab#163)
    - give easier option for transferring SSL client files from Malcolm to forwarder (idaholab#177)
        + added `tx-rx-secure.sh` script as wrapper around [croc](https://github.com/schollz/croc) automatically creating and using a local-only relay

* Component version updates
    - [Zeek v5.2.0](https://github.com/zeek/zeek/releases) (idaholab#161)
    - [fluent bit v2.0.10](https://fluentbit.io/announcements/v2.0.10/)
    - [NetBox v3.4.7](https://github.com/netbox-community/netbox/releases/tag/v3.4.7)

* Fixes
    - XFCE4's "save session on exit" causes conflict with Hedgehog kiosk mode if firefox instance is started upon session restore (idaholab#164)
    - docker-compose move from go-yaml/v3 breaks Malcolm's docker-compose YAML files (idaholab#178, docker/compose#10411)
    - increase index.mapping.nested_fields.limit in opensearch index template (idaholab#180)
spaceo added a commit to danskernesdigitalebibliotek/dpl-cms that referenced this issue Apr 13, 2023
Make shure we have unique yaml keys.
Inspired by this post:
docker/compose#10411 (comment)
spaceo added a commit to danskernesdigitalebibliotek/dpl-cms that referenced this issue Apr 14, 2023
Make shure we have unique yaml keys.
Inspired by this post:
docker/compose#10411 (comment)
akabiru added a commit to akabiru/openproject that referenced this issue Apr 17, 2023
`docker compose` v2.17.2 fails with the following syntax error due to
go/yaml/v3 update.

```sh
❯ docker compose config
yaml: unmarshal errors:
  line 40: mapping key "<<" already defined at line 39
  line 40: mapping key "<<" already defined at line 39
  line 40: mapping key "<<" already defined at line 39
```

"goyaml/v3 does not support repeated anchors (due to internal storage
using << as key during parsing) but allows use of multi-values in
anchors"

See: docker/compose#10411 (comment)
     https://yaml.org/type/merge.html
b12f pushed a commit to opf/openproject that referenced this issue Apr 17, 2023
…jected from v2.17.x (#12428)

fix: Replace unsupported repeated yaml anchors with merge

`docker compose` v2.17.2 fails with the following syntax error due to
go/yaml/v3 update.

```sh
❯ docker compose config
yaml: unmarshal errors:
  line 40: mapping key "<<" already defined at line 39
  line 40: mapping key "<<" already defined at line 39
  line 40: mapping key "<<" already defined at line 39
```

"goyaml/v3 does not support repeated anchors (due to internal storage
using << as key during parsing) but allows use of multi-values in
anchors"

See: docker/compose#10411 (comment)
     https://yaml.org/type/merge.html
gurdiga added a commit to gurdiga/rss-email-subscription that referenced this issue Apr 28, 2023
Fix this error:

docker-compose --file docker-compose.yml config
parsing /Users/vlad/src/rss-email-subscription/docker-compose.yml: yaml: unmarshal errors:
  line 56: mapping key "<<" already defined at line 55
  line 84: mapping key "<<" already defined at line 83
  line 103: mapping key "<<" already defined at line 102
  line 118: mapping key "<<" already defined at line 117
  line 136: mapping key "<<" already defined at line 135
  line 154: mapping key "<<" already defined at line 153
  line 168: mapping key "<<" already defined at line 167

NOTE: This started after Docker update, which used a newer version of
YAML library. Please see docker/compose#10411.
louisroyer added a commit to louisroyer/test-mec that referenced this issue May 4, 2023
abates added a commit to abates/nautobot-plugin-data-validation-engine that referenced this issue May 5, 2023
Repeated anchors are not allowed in YAML, the values should be a list. See docker/compose#10411 (comment)
spaceo added a commit to danskernesdigitalebibliotek/dpl-cms that referenced this issue May 9, 2023
Make shure we have unique yaml keys.
Inspired by this post:
docker/compose#10411 (comment)
abates added a commit to nautobot/nautobot-app-design-builder that referenced this issue May 11, 2023
Docker compose no longer allows multiple merge keys
in compose files. The YAML spec allows multiple maps
to be merged by passing a sequence to the merge (`<<:`)
key. This is documented in the
[YAML spec](https://yaml.org/type/merge.html). The behavior
change for docker-compose is documented in
[this issue](docker/compose#10411)
abates added a commit to nautobot/nautobot-app-design-builder that referenced this issue May 11, 2023
Docker compose no longer allows multiple merge keys
in compose files. The YAML spec allows multiple maps
to be merged by passing a sequence to the merge (`<<:`)
key. This is documented in the
[YAML spec](https://yaml.org/type/merge.html). The behavior
change for docker-compose is documented in
[this issue](docker/compose#10411)
abates added a commit to nautobot/nautobot-app-design-builder that referenced this issue May 11, 2023
Docker compose no longer allows multiple merge keys
in compose files. The YAML spec allows multiple maps
to be merged by passing a sequence to the merge (`<<:`)
key. This is documented in the
[YAML spec](https://yaml.org/type/merge.html). The behavior
change for docker-compose is documented in
[this issue](docker/compose#10411)
abates added a commit to abates/nautobot-ssot-vsphere that referenced this issue May 17, 2023
Repeated anchors are not allowed in YAML, the values should be a list. See docker/compose#10411
abates added a commit to abates/nautobot-ssot-vsphere that referenced this issue May 17, 2023
Repeated anchors are not allowed in YAML, the values should be a list. See docker/compose#10411
abates added a commit to abates/nautobot-ssot-vsphere that referenced this issue May 17, 2023
Repeated anchors are not allowed in YAML, the values should be a list. See docker/compose#10411
chrnie added a commit to chrnie/docker-compose-icinga that referenced this issue May 25, 2023
docker/compose#10411

repeated "<<" break docker-compose >= 2.17

yaml: unmarshal errors:
  line 148: mapping key "<<" already defined at line 147
physikerwelt added a commit to MaRDI4NFDI/portal-compose that referenced this issue Jul 24, 2023
* duplicate key in docker-compose-dev
* [deprecated syntax](docker/compose#10411 (comment)) in docker-compose
TanjinAlam added a commit to TanjinAlam/quorum-dev-quickstart that referenced this issue Oct 19, 2023
YAML parsing was improved in v2.17 - multiple merge keys takes as array 

issue taken from docker/compose#10411
Skitionek added a commit to biosustain/lifelike that referenced this issue Jan 8, 2024
Skitionek added a commit to biosustain/lifelike that referenced this issue Jan 8, 2024
Skitionek added a commit to biosustain/lifelike that referenced this issue Jan 8, 2024
Skitionek added a commit to biosustain/lifelike that referenced this issue Jan 8, 2024
NoNamePaul94 added a commit to dc-ag/packeton that referenced this issue Apr 19, 2024
Issue when using docker compose version >= 2.17.0

docker/compose#10411
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants
@ndeloof @arulrajnet @gowrizrh and others