You're facing this error because using an old version of the compose command, docker-compose. A newer version is available i.e., docker compose (notice the missing -)
Here's a step-by-step guide on how to solve this error:
You'll have to remove the old version of docker-compose. Run sudo apt-get remove docker-compose;
In the event where you installed docker-compose using the curl command, you should remove it using: sudo rm /usr/local/bin/docker-compose
Install Docker Compose v2
Update: sudo apt-get update;
Create a directory to store the CLI Plugin: mkdir -p ~/.docker/cli-plugins;
Download the docker compose binary: curl -SL https://github.com/docker/compose/releases/download/v2.36.2/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-compose
Make the binary executable: chmod +x ~/.docker/cli-plugins/docker-compose
Verify your installation: docker compose version
[If using a yml file] Now you can go ahead and run docker compose -f docker/docker-compose.prod.yml build <service_name>
[If not using ayml file] Just cd to the directory where you have the Dockerfile, and use docker compose build