How can I fix this issue with Yaml file?

Viewed 41

Hi I am trying to run docker-compose build --no-cache but I keep getting errors.

yaml.parser.ParserError: while parsing a block mapping
  in ".\docker-compose.yml", line 1, column 1
expected <block end>, but found '<block mapping start>'
  in ".\docker-compose.yml", line 2, column 5
docker-compose.yml:
   

Please help me to to format this I looked online but I couldn't find any linter that could do this I keep getting errors. Thanks. This is my docker composer file: s is my docker file docker-compose.yml

   version: '3'
    services:
     #PHP-FPM service
        app:
            build:
                context: .
                dockerfile: Dockerfile
            container_name: store
            restart: unless-stopped
            tty: true
            working_dir: /var/www
             volumes:
                - ./:/var/www
                - ./docker-files/php/local.ini:/usr/local/etc/php/conf.d/local.ini
             networks:
                -app-network
    
            #Nginix service
            webserver:
                image: nginx-alpine
                container_name: store-webserver
                restart: unless-stopped
                tty: true
                ports:
                    - "8100:80"
                    - "8143:443"
                volumes:
                    - ./:/var/www
                    - ./docker-files/nginx/conf.d:/etc/nginx/conf.d/
                networks:
                    -app-network
            #MariaDB service
            db:
                image: mariadb:10.5.6
                container_name: store-mariadb
                restart: unless-stopped
                tty: true
                ports:
                    - "3306:3306"
                environment:
                    MYSQL_ROOT_PASSWORD: root
                    MYSQL_DATABASE: store
                    MYSQL_USER: store
                    MYSQL_PASSWORD: root
                volumes:
                    - mariadbData:/var/lib/mysql
                    - ./docker-files/mariadb/my.cnf:/etc/mysql/my.cnf
                networks:
                    -app-network
            #Volumes
            volumes:
                mariadbData:
                    driver: local
            #Networks
            networks:
                app-network:
                    driver: bridge
1 Answers

I have noticed some spacing issues on your YAML file, one of them is that the version and services sections are not on the same level, you have to know that docker-compose files and YAML have a strict syntax and a spacing might ruin everything for you here is a fix to your compose file, make sure to learn and read more about docker-compose documentation. Not sure what's the behavior of your environment but here is a correct YAML syntax for your example:

version: '3'
services:
  #PHP-FPM service
    app:
        build:
            context: .
            dockerfile: Dockerfile
        container_name: store
        restart: unless-stopped
        tty: true
        working_dir: /var/www
        volumes:
          - ./:/var/www
          - ./docker-files/php/local.ini:/usr/local/etc/php/conf.d/local.ini
        networks:
            - app-network

    #Nginix service
    webserver:
        image: nginx-alpine
        container_name: store-webserver
        restart: unless-stopped
        tty: true
        ports:
            - "8100:80"
            - "8143:443"
        volumes:
            - ./:/var/www
            - ./docker-files/nginx/conf.d:/etc/nginx/conf.d/
        networks:
            - app-network
    #MariaDB service
    db:
        image: mariadb:10.5.6
        container_name: store-mariadb
        restart: unless-stopped
        tty: true
        ports:
            - "3306:3306"
        environment:
            MYSQL_ROOT_PASSWORD: root
            MYSQL_DATABASE: store
            MYSQL_USER: store
            MYSQL_PASSWORD: root
        volumes:
            - mariadbData:/var/lib/mysql
            - ./docker-files/mariadb/my.cnf:/etc/mysql/my.cnf
        networks:
            - app-network
#Volumes
volumes:
    mariadbData:
        driver: local
#Networks
networks:
    app-network:
        driver: bridge
Related