[Fixed]-Error Map Keys Must be unique while using YAML extension field in docker compose for django application

42👍

<<: *reference isn’t actually a keyword; it’s an ordinary YAML mapping entry with the key << that happens to have special treatment. On SO, see What is the << (double left arrow) syntax in YAML called, and where’s it specced?; that in turn refers to the Merge Key Language-Independent Type for YAML™ Version 1.1 draft specification.

Since << is a mapping key, YAML parsers that try to convert mappings into dictionaries won’t like to see multiple of it. Conversely, the spec allows a sequence as the value, so for this specific use you could write

<<: [*django-build, *common]

(Also consider whether you need this many custom settings. Compose provides a network named default for you so you don’t typically need networks:; if you just name your Dockerfile, well, Dockerfile then you can use a one-liner build: . That would avoid needing the YAML alias/anchor syntax here.)

Leave a comment