Your platform generated non compliant code and DOES NOT WORK

ubuntu@instance-20221009-1127:~$ docker-compose up -d
ERROR: yaml.scanner.ScannerError: mapping values are not allowed here
  in "./docker-compose.yml", line 2, column 8
ubuntu@instance-20221009-1127:~$ sudo nano docker-compose.yml
ubuntu@instance-20221009-1127:~$ docker-compose up -d
ERROR: yaml.scanner.ScannerError: while scanning a quoted scalar
  in "./docker-compose.yml", line 31, column 1
found unexpected end of stream
  in "./docker-compose.yml", line 32, column 1
ubuntu@instance-20221009-1127:~$

Well, read the error messages, your docker-compose.yml file is not correct.

Generated by your system.

I removed the echo on the top line which serves no purpose and caused the first error, and got a second error.

echo '
version: "3.9"

services:
  # Start the agent with the latest version
  hub-agent:
    image: ghcr.io/traefik/hub-agent-traefik:v1.0.0
    pull_policy: always
    container_name: hub-agent
    restart: "on-failure"
    command:
      - run
      - --hub.token=xxxxx
      - --auth-server.advertise-url=http://hub-agent
      - --traefik.host=traefik
      - --traefik.tls.insecure=true
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    depends_on:
      - traefik

  # Start Traefik with the latest version
  traefik:
    image: traefik:v2.8
    container_name: traefik
    command:
      # Enable Hub communication (open the port 9900 and 9901 by default)
      - --experimental.hub=true
      - --hub.tls.insecure=true
      - --metrics.prometheus.addrouterslabels=true

' > ./docker-compose-hub-agent.yaml && docker-compose -f ./docker-compose-hub-agent.yaml up -d

What do you mean by that???

What I mean is that code was generated by your system, i.e. there's a link somewhere in your traefik hub that says copy and paste this code into a .yml file and it will auto detect what docker is doing and set everything up for you, etc etc, and I did that and it errored.

I'm trying to decide whether to stick with docker or get rid of it altogether, just think containerising everything leads to more middleware which doesn't work as well as the software it is trying to fix.

You should not share your token publicly.
The code is supposed to be pasted in a terminal / shell.

echo '
XXX
YYY
ZZZ
' >  > ./docker-compose-hub-agent.yaml && docker-compose -f ./docker-compose-hub-agent.yaml up -d

It will put the content between quote in docker-compose-hub-agent.yaml and launch docker-compose after.

Does it answer your question ?