Docker compose build error - 'services must be a mapping'

Hi There,
I am running Docker compose build and getting error - ‘services must be a mapping’.
I googled and referred similar issue. But still no luck.
Can you please help?
My YAML file content is given below.

I am on Windows 10.
My Docker version 20.10.14, build a224086
Docker Compose version v2.5.0

version: '2.5.0'
services:
web:
  build: .
  command: bash -c 'node app.js'
  working_dir: /usr/src/app
  environment:
    PORT: 8050
    NGINX_PORT: 8443
  volumes:
    - './views:/app/user/views:ro'
nginx:
  build: nginx
  ports:
    - '8080:80'
    - '8443:443'
  links:
    - 'web:web'
  volumes_from:
    - web

Thanks,
Pragash

Please, use the code block button (</>) to insert source codes or anything in which the proper indentation is important or contains special characters which means something in MarkDown. I fixed your post.

There are multiple problems here.

  • First of all, the version doesn’t seem right. That version was the version of the compose file not the version of Docker Compose as a software. Docker Compose v2 does no require a version number in the compose file anyway, so remove that line.
  • The other problem is the indentation. “web” and “nginx” should be indented like this:
services:
  web:
    build: .
    command: bash -c 'node app.js'
    working_dir: /usr/src/app
    environment:
      PORT: 8050
      NGINX_PORT: 8443
    volumes:
      - './views:/app/user/views:ro'
  nginx:
    build: nginx
    ports:
      - '8080:80'
      - '8443:443'
    links:
      - 'web:web'
    volumes_from:
      - web

Thanks very much @rimelek