ERROR: yaml.scanner.ScannerError: mapping values are not allowed here in "./docker-compose.yml", line 27, column 18

Viewed 19
version: "3"
services:
  strapi:
    build: ./
    container_name: cms
    restart: unless-stopped
    networks:
      - local
    environment:
      DATABASE_CLIENT: postgres
      DATABASE_NAME: strapi
      DATABASE_HOSTS: "postgres:5432"
      DATABASE_PORT: 5432
      DATABASE_USERNAME: "banana"
      DATABASE_PASSWORD: "banana"
    volumes:
      - ./src/api:/srv/app/api
      - ./src/components:/srv/app/components
      - ./src/config:/srv/app/config
      - ./src/extensions:/srv/app/extensions
      - ./src/search:/srv/app/search
      - ./data/assets:/srv/app/public/uploads
    ports:
      - "1337:1337"
    depends_on:
      - metrics
        condition: service_completed_successfully
      - postgres
        condition: service_completed_successfully

So it can only be fixed if i remove condition: service_completed_successfully, but it doesn't make sense that it does that.

The error is thrown when I run docker-compose up.

1 Answers

Compose file version 3 depends_on: doesn't support conditions on dependencies, so you'd need to delete the condition: lines.

version: "3" # means 3.0; also consider 3.8
...
  depends_on: # in version 3 must only be a list of string names
    - metrics
    - postgres

For a couple of purposes it's useful to use Compose file version 2. Its depends_on: supports either a list of strings, or a mapping where the keys are other service names and the values include those conditions.

version: "2.4"
...
  depends_on:
    metrics: # no leading `-`, with trailing `:`
      condition: service_completed_successfully
    postgres:
      condition: service_completed_successfully

If you have a very current version of the Compose tool then you can use the Compose specification format. This has some incompatibilities with the other formats and may not work if docker-compose --version reports something like docker-compose version 1.29.2. It supports both forms of depends_on:.

The syntax you have in the question isn't valid YAML. - name on one line looks like it's a list item containing a string, but then indented key: value on the following line looks like it's adding an additional value to a mapping dictionary. That's where you're getting the YAML parse error.

Related