Search code examples
postgresqldockerdocker-composedrupal

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?


Solution

  • 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: