skip to Main Content

I always get this error

yaml: line XX: mapping values are not allowed in this context

this is the part of my yaml file (for zabbix)

  web-nginx:
    image: 'zabbix/zabbix-web-nginx-pgsql:alpine-trunk'
    restart: unless-stopped
    tty: true
    environment:
      ZBX_SERVER_HOST=xxx
      DB_SERVER_HOST=xxx
      POSTGRES_USER=xxx
      POSTGRES_PASSWORD=xxx
      POSTGRES_DB=xxx
      PHP_TZ=xxx
      ZBX_SSO_SETTINGS="{"strict": false, "baseurl": "https://xxx", "use_proxy_headers": true}"

I already tried atleast these combinations

  1. ZBX_SSO_SETTINGS="{"strict": false, "baseurl": "https://xxx", "use_proxy_headers": true}"
  2. "ZBX_SSO_SETTINGS={"strict": false, "baseurl": "https://xxx", "use_proxy_headers": true}"
  3. ZBX_SSO_SETTINGS='{"strict": false, "baseurl": "https://xxx", "use_proxy_headers": true}'

2

Answers


  1. Chosen as BEST ANSWER

    using

    - ZBX_SSO_SETTINGS="{"strict":false,"baseurl":"https://xxx","use_proxy_headers":true}"

    fixed the issue, so using -, =, escaping " and removing the spaces of the json

    probably because yaml is space dependent?


  2. I’d make two changes here.

    Compose environment: has two syntaxes. It either needs to be a YAML list (- KEY=value) or a mapping (KEY: value). The format you have with multiple lines of KEY=value won’t work. I’d choose the mapping syntax here

    environment:
      ZBX_SERVER_HOST: xxx
      DB_SERVER_HOST: xxx
                    ^^ note, colons and not equals signs here
    

    In this syntax, the keys and values are separate YAML scalars. This means you can use YAML block scalar syntax. If a key has no value except that it ends with | (with some optional whitespace controls) and the following lines are indented, then those following lines are read as a multi-line string. The part that is the string is identified by it being indented, so there is no more quoting or escaping required. > is similar except that newlines are converted to spaces.

    So if you directly needed to pass a JSON object string in an environment variable, you might do it as a YAML block scalar

    environment:
      ZBX_SSO_SETTINGS: >-
        {"strict": false, "baseurl": "https://xxx", "use_proxy_headers": true}
    

    With the > form, you can also optionally split this out across multiple lines, and they’ll be joined and separated by spaces.

    environment:
      ZBX_SSO_SETTINGS: >-
        {
          "strict": false,
          "baseurl": "https://xxx",
          "use_proxy_headers": true
        }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search