Why am I getting "Volumes must be mapping" error

Question:

Trying to add Django app with a PostgreSQL db to a Docker container. When trying to run "docker-compose build", I am getting a "Volumes must be mapping" error. Not sure what I’m doing wrong as it looks like the : syntax signified a mapping.

When I remove the volumes sections entirely the build continues (with or without a Dockerfile reference so I’ve omitted that part).

See docker-compose.yml:

version: "3.9"

services:
  app:
    build:
      context: .
      args:
      - DEV=true
    ports:
      - "8000:8000"
    volumes:
      - dev-static-data:/backend/django_static
    command: >
      sh -c "python manage.py wait_for_db &&
             python manage.py migrate &&
             python manage.py runserver 0.0.0.0:8000"
    environment:
      - DB_HOST=db
      - DB_NAME=devdb
      - DB_USER=devuser
      - DB_PASS=changeme
      - DEBUG=1
    depends_on:
      - db
      - redis

  db:
    image: postgres:15-alpine
    volumes:
      - dev-db-data:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=devdb
      - POSTGRES_USER=devuser
      - POSTGRES_PASS=changeme

volumes:
  - dev-db-data:
  - dev-static-data:

Any ideas?

Asked By: Conor Romano

||

Answers:

The volumes section at the end of Docker Compose file is expecting a mapping (key-value pairs) instead of an array (list). To fix this, the configuration should be written like this:

volumes:
    dev-db-data:
    dev-static-data:
Answered By: kamran890