首页 > 解决方案 > 错误:Compose 文件“.\docker-compose.yml”无效,因为:services.drupal 的配置选项不受支持:“postgres”

问题描述

这是我的 docker-compose.yml

version: "3"

services:
    drupal:
        image: drupal
        ports:
        - "8080:80"
        volumes:
        - drupal-modules:/var/www/html/modules
        - drupal-profiles:/var/www/html/profiles
        - drupal-sites:/var/www/html/sites
        - drupal-themes:/var/www/html/themes
        postgres:
            image: postgres
            environment:
                - POSTGRES_PASSWORD=mypasswd

volumes:
    drupal-modules:
    drupal-profiles:
    drupal-sites:
    drupal-themes:

当我跑步时

$ docker-compose up

我得到:

ERROR: The Compose file '.\docker-compose.yml' is invalid because:
Unsupported config option for services.drupal: 'postgres'

有什么问题?

标签: postgresqldockerdocker-composedrupal

解决方案


你的缩进docker-compose.yml是不正确的,因为.yml文件是缩进敏感的。

你有三个错误:

  1. ports是一个key:value数据,所以-应该在下一行缩进。
  2. volumes是一个key:value数据,所以-应该在下一行缩进。
  3. postgres服务的缩进应该与drupal.

所以你的文件应该看起来像这样才能工作:

version: "3"

services:
    drupal:
        image: drupal
        ports:
            - "8080:80"
        volumes:
            - drupal-modules:/var/www/html/modules
            - drupal-profiles:/var/www/html/profiles
            - drupal-sites:/var/www/html/sites
            - drupal-themes:/var/www/html/themes
    postgres:
        image: postgres
        environment:
            - POSTGRES_PASSWORD=mypasswd

volumes:
    drupal-modules:
    drupal-profiles:
    drupal-sites:
    drupal-themes:

推荐阅读