Home > other >  I get error message 'Version in "./docker-compose.yaml" is invalid - it should be a s
I get error message 'Version in "./docker-compose.yaml" is invalid - it should be a s

Time:03-12

I get this error message when i run command - docker-comose up

ERROR: Version in "./docker-compose.yaml" is invalid - it should be a string.

My docker-compose file:

    version: 3.9
    services:
      backend:
        build: .
        ports:
          - 8080:8080
        volumes:
          - ./:app
        depends_on:
          - db
      db:
        image: mysql:8
        restart: always
        environment:
          MYSQL_DATABASE: ambassador
          MYSQL_USER: root
          MYSQL_PASSWORD: root
          MYSQL_ROOT_PASSWORD: root
        volumes:
          - ./storage/dbdata:/var/lib/mysql
        ports:
          - 3306:3306

CodePudding user response:

The error message is quite clear here:

Version in "./docker-compose.yaml" is invalid - it should be a string.

The version is specified as a number but should be a string, i.e.:

version: "3.9"

Without explicit quotes the yaml parser will try to infer the type of the specified value. In this case 3.9 looks like a floating point number so the parser will parse it as a number - but the docker-compose specification requires it to be a string; so you have to explicitly quote it here.

Same goes e.g. for the values true and false: without explicit quoting the yaml parser will parse these as boolean values, throwing an error if they are used at places where a string value is expected.

  • Related