How to fix docker-compose: services.my-service Additional property volume is not allowed

Problem:

When you try to start your docker-compose based service using

docker-compose up

you see the following error message

services.my-service Additional property volume is not allowed

with a config such as

services:
  mariadb:
    image: 'mariadb:latest'
    environment:
      - MYSQL_ALLOW_EMPTY_PASSWORD=yes
      - MYSQL_DATABASE=redmine
    volume:
      - './mariadb_data:/var/lib/mysql'

Solution

You’ve mis-spelled volume: - it always needs to be called volumes: even if there is only a single volume:

services:
  mariadb:
    image: 'mariadb:latest'
    environment:
      - MYSQL_ALLOW_EMPTY_PASSWORD=yes
      - MYSQL_DATABASE=redmine
    volumes:
      - './mariadb_data:/var/lib/mysql'