0

I am working on a shared project, that contains a docker compose file with structure as below. (Confidential info removed)

version: "3.9"
# https://docs.docker.com/compose/compose-file/

x-common-variables: &common-variables
  JAVA_TOOL_OPTIONS: -XX:MaxRAMPercentage=60.0 -Dlogging.level.com.backbase=DEBUG
  ... More common variables

x-database-variables: &database-variables
  spring.liquibase.enabled: true
  ... More DB Variables

x-message-broker-variables: &message-broker-variables
  spring.activemq.broker-url: tcp://message-broker:61616
  ... More message broker variables

x-healthcheck-defaults: &healthcheck-defaults
  start_period: 60s
  ... more defaults

services:
  mysql:
    ... More details

  message-broker:
    ... More details


  serviceName:
    container_name: containerName
    image: imagePath
    ports:
      - "8080:8080"
    environment:
    // Following line works
      <<: *common-variables
      
   

  another-service:
    container_name: another-container
    image: another-image-path
    ports:
      - "8040:8080"
    environment:
      <<: *common-variables
       // BREAKS HERE
      <<: *message-broker-variables
      <<: *database-variables
    

The ingestion of variables via "<<" works for one service, but breaks for another with the following

line 138: mapping key "<<" already defined at line 137

I am using docker version

Docker version 24.0.2-rd, build e63f5fa
colima version 0.5.4
git commit: feef4176f56a7dea487d43689317a9d7fe9de27e

runtime: docker
arch: x86_64
client: v24.0.2-rd
server: v20.10.20

The same file works on other dev machines (I am not sure of their config). Kindly suggest what could be the cause of this issue?

Mohit Kanwar
  • 2,962
  • 7
  • 39
  • 59
  • Don't just strip out random parts, extract a [mcve] instead. – Ulrich Eckhardt Aug 05 '23 at 08:50
  • `<<:` isn't syntactically special; it is a map key `<<` that has a special value. You can only use `<<:` once in a given YAML map, but it can have a list value `<<: [*common-variables, *message-broker-variables, *database-variables]`. – David Maze Aug 05 '23 at 10:22

1 Answers1

0

I was not able to find an appropriate answer. I am still looking for an answer, however below is the workaround I am using.

I manually replaced all the environment variables that it was trying to import by << command.

This means duplicate code, and additional effort while merging the code. But at least it works.

Mohit Kanwar
  • 2,962
  • 7
  • 39
  • 59