Docker-撰写文件抛出 yaml.scanner.ScannerError 错误

Docker-Compose file throwing yaml.scanner.ScannerError error

这是我的 docker-compose 文件的样子

version: '3.3'
    services:
        frontend:
            ports:
                - 8000:8000
            build: ./frontend
        api:
            build: ./api
            ports: 
                - 8080:8080
        reverse-proxy:
            image: nginx:1.21
            depends_on: 
                - api
                - frontend
            volumes:
                - ./nginx-conf:/etc/nginx/conf.d
            ports: 
            - 80:80
            - 443:443

i 如果我 运行 docker-compose build on the above file 我收到以下错误

ERROR: compose.cli.main.main: yaml.scanner.ScannerError: while scanning for the next token found character '\t' that cannot start any token in "./docker-compose.yaml", line 3, column 1

我尝试过更改版本并更正 spaces/tabs 但没有任何效果

servicesversion 的缩进应该在同一层级,因此您的 docker-compose 文件应该如下所示:

version: '3.3'

services:
    frontend:
        ports:
            - 8000:8000
        build: ./frontend
    api:
        build: ./api
        ports: 
            - 8080:8080
    reverse-proxy:
        image: nginx:1.21
        depends_on: 
            - api
            - frontend
        volumes:
            - ./nginx-conf:/etc/nginx/conf.d
        ports: 
        - 80:80
        - 443:443