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

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"

  # Start the agent with the latest version
    pull_policy: always
    container_name: hub-agent
    restart: "on-failure"
      - run
      - --hub.token=xxxxx
      - --auth-server.advertise-url=http://hub-agent
      - --traefik.tls.insecure=true
      - /var/run/docker.sock:/var/run/docker.sock
      - traefik

  # Start Traefik with the latest version
    image: traefik:v2.8
    container_name: traefik
      # 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 '
' >  > ./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 ?