Unsupported Config option for services: profiles

Here’s the error message on running docker-compose build:
ERROR: The Compose file ‘./docker-compose.yml’ is invalid because:
Unsupported config option for services.cache: ‘profiles’

And here’s my docker-compose.yml

version: "3.9"
services:
    cache:
        image: redis:latest
        profiles:
          - tools

docker-compose --version
docker-compose version 1.27.4, build unknown

docker -v
Docker version 20.10.2, build 2291f61

lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.2 LTS
Release: 20.04
Codename: focal

Support for service profiles was added in docker-compose version 1.28