Docker Compose Unsupported Option 'additional_contexts'

I am getting the error:

ERROR: The Compose file './docker-compose.yml' is invalid because:
services.api.build contains unsupported option: 'additional_contexts'

When I try to run docker-compose commands but, they are supported: Compose Build Specification | Docker Docs

My compose file:

version: '3.8'
services:
  api:
    build:
      dockerfile: ./backend/Dockerfile
      context: ./
      additional_contexts:
        - data=./backend
      args:
        - ENVIRONMENT=$ENVIRONMENT
    container_name: api
    environment:
      - MODE=$MODE
    depends_on:
      database:
        condition: service_healthy
    ports:
      - 9999:9999
    networks:
      - backend
    restart: always

Can anyone help me with this?

Make sure to use docker compose (=v2) and not docker-compose (=v1). V1 got deprecated in June 2023.

V2 should have been installed as a dependency to either docker-ce or as part of Docker Desktop.

In case the command docker compose is not available on your systeme (or uses the old plugin for cloud deployments), make sure to follow the installations instructions: Migrate to Compose V2 | Docker Docs

1 Like

Thank you very much, that was exactly it, the outdated compose version. I had to download the standalone version from the website manually and now everything works. It actually surprises me a little that this package in my distro is not updated (I use Debian SID).

Are you sure you installed docker-ce from docker’s repos?
Maybe you installed the docker.io package from Debian’s repos, which might result in a different experience than using vanilla docker from docker’s repos.