Compose yaml.parser error

services: 
    nginx: 
      image: nginx:1.13 
      ports: 
       - 80:80 
      volumes: 
       - ./src:/usr/share/nginx/html 

    apache: 
      image: httpd:2.4 
      ports: 
       - 8080:8080 
      volumes: 
       - ./src:/usr/local/apache2/htdocs 

    db: 
      image: mariadb 
      ports: 
        - 4000:4000 

ERROR: yaml.parser.ParserError: expected ‘’, but found ‘’ in “./docker-compose.yml”, line 7, column 1
ERROR: yaml.parser.ParserError: expected ‘’, but found ‘’ in “./docker-compose.yml”, line 7, column 1

Hi,

Since your yaml file doesn’t include the “version” directive, compose will assume you mean to use version 1 commands. This is intended largely for legacy engines and relatively basic engine features from around engine 1.9. Please see the following link for more details: https://docs.docker.com/compose/compose-file/compose-versioning/#version-1

I also notice that your ports listing are not quoted. That can sometimes cause problems with the parser. For some examples of ports directives, please see https://docs.docker.com/compose/compose-file/#ports

I ran your YAML using a recent engine, quoted the port definitions, and pre-pended a line with version: ‘3’, and was able to run docker-compose config command, as well as docker-compose up and docker-compose down.

You don’t mention which version of docker-compose you are using, nor which engine; those may also have an effect on the errors you may see.

docker-compose version 1.21.2, build a133471
docker version 17.05.0-ce, build 89658be
also I quoted ports,but nothing changed