运行时出错。 YAML林特显示无错误

时间:2019-08-21 16:09:53

标签: docker-compose

在为我的yml文件运行docker-compose时,我不断收到服务“图像”错误。

我在线上进行了研究,看来这主要是一些格式化错误。 我已经通过yAML linter运行yml,并且没有错误。

version: '3.5'
services:
  server: 
  image: postgrest/postgrest
  ports:
    - "3000:3000"
  links:
      - db:db
  environment:
      PGRST_DB_URI: postgres://app_user:password@db:5432/app_db
      PGRST_DB_SCHEMA: public
      PGRST_DB_ANON_ROLE: app_user
      depends_on:
      - db
      db:
      image: postgres
      ports:
        - "5432:5432"
      environment:
        POSTGRES_USER: ${POSTGRES_USER:-postgres}
        POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-changeme}
        PGDATA: /data/postgres
      volumes:
       - postgres:/data/postgres      

      networks:
        - postgres
      restart: unless-stopped

      pgadmin:
        container_name: pgadmin_container
        image: dpage/pgadmin4
        environment:
        PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:-pgadmin4@pgadmin.org}
        PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin}
        volumes :
        - pgadmin:/root/.pgadmin
        ports: 
          -"${PGADMIN_PORT:-5050}:80"
        networks:
        - postgres
        restart: unless-stopped

networks:
  postgres:
    driver: bridge

volumes:
    postgres:
    pgadmin:

swagger:
  image: swaggerapi/swagger-ui
  ports:
    - "8080:8080"
  expose:
    - "8080"
  environment:
    API_URL: http://localhost:3000/

预计将下载图像并启动容器

错误是:  错误:在文件'。\ docker-compose.yml'中,服务'image'必须是映射,而不是字符串。

1 个答案:

答案 0 :(得分:1)

此问题是由于缩进而发生的。

docker-compose由于错误的缩进而像服务一样image

我修改了文件并成功启动了已配置的容器:

version: "3.5"

services:
        server:
                image: postgrest/postgrest
                ports:
                         - "3000:3000"
                links:
                         - db:db
                environment:
                       PGRST_DB_URI: postgres://app_user:password@db:5432/app_db
                       PGRST_DB_SCHEMA: public
                       PGRST_DB_ANON_ROLE: app_user
                depends_on:
                         - db
        db:
                image: postgres
                ports:
                        - "5432:5432"
                environment:
                        POSTGRES_USER: ${PGADMIN_DEFAULT_EMAIL:-pgadmin4@pgadmin.org}
                        POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-changeme}
                        PGDATA: /data/postgres
                volumes:
                        - postgres:/data/postgres
                networks:
                        - postgres
                restart: unless-stopped
        pgadmin:
                container_name: pgadmin_container
                image: dpage/pgadmin4
                environment:
                        PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:-pgadmin4@pgadmin.org}
                        PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin}
                volumes:
                        - pgadmin:/root/.pgadmin
                ports:
                        - "${PGADMIN_PORT:-5050}:80"
                networks:
                        - postgres
                restart: unless-stopped

        swagger:
                image: swaggerapi/swagger-ui
                ports:
                        - "8080:8080"
                expose:
                        - "8080"
                environment:
                        API_URL: http://localhost:3000/

networks:
        postgres:
                driver: bridge

volumes:
        pgadmin:
        postgres: