linuxdockerdocker-composecontainerscommand-line-interface

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: https://docs.docker.com/compose/compose-file/build/#additional_contexts

EDIT 1:

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

EDIT 2:

Output docker-compose version:

docker-compose version 1.29.2, build unknown
docker-py version: 5.0.3
CPython version: 3.11.6
OpenSSL version: OpenSSL 3.0.12 24 Oct 2023

Can anyone help me with this?


Solution

  • You might want to upgrade docker-compose.

    Support for additional_context has been added with version 2.17.0

    see https://docs.docker.com/compose/release-notes/#2170