简体   繁体   中英

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

Here is my 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:

As I run

$ docker-compose up

I get:

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

what's the problem?

Every time you see

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

it is likely the problem lies in wrong indent, as this is the case.

First, both postgres and drupal are containers (so services ), and so they must have the same indent level, that is, one indentation level less than services .
Put one indentation level less to the whole postgres structure/tree.

Second, every element starting with - must have one indent level more than the element it belongs to.
So add one more indent level to the elements of ports and volumes .

Here is the docker-compose.yml corrected:

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:

Indentation in your docker-compose.yml is not correct, since .yml files are indent-sensitive.

You have three errors:

  1. ports is a key:value data, so - should be indented in the next line.
  2. volumes is a key:value data, so - should be indented in the next line.
  3. postgres service's indentation should be in the same level as drupal .

So your file should look like this to work:

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM