Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker-compose build contains unsupported option: 'network'

I'm trying to make docker-compose run through system proxy, and according to docker compose file doc

network option could be added in compose file like this:

build:
  context: .
  network: host

And my compose file looks like this:

version: '3'
services:
  flasky:
    build:
      context: "."
      network: host
      args:
        - http_proxy
        - https_proxy 
    ports:
      - "8000:5000"
    env_file: .env
    restart: always
    links:
      - mysql:dbserver
      - elasticsearch:elasticsearch
  mysql:
    image: "mysql/mysql-server:5.7"
    env_file: .env-mysql
    restart: always
  elasticsearch:
    image: "docker.elastic.co/elasticsearch/elasticsearch:7.8.0"
    env_file: .env-es
    restart: always

When trying to run "docker-compose up", I get the following error:

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

I think i did exactly as the example in doc, no ideas what is wrong here. Any help?

like image 778
oeter Avatar asked Nov 16 '25 02:11

oeter


1 Answers

From your documentation article:

Added in version 3.4 file format

Source: https://docs.docker.com/compose/compose-file/#network

But you are on version 3.0

See:

Note: When specifying the Compose file version to use, make sure to specify both the major and minor numbers. If no minor version is given, 0 is used by default and not the latest minor version. As a result, features added in later versions will not be supported. For example:

version: "3"

is equivalent to:

version: "3.0"

Source: https://docs.docker.com/compose/compose-file/compose-versioning/#version-3

So your fix would just be to change your version from version: 3 to, at least, version: 3.4

version: '3.4'
services:
  flasky:
    build:
      context: "."
      network: host
      args:
        - http_proxy
        - https_proxy 
    ports:
      - "8000:5000"
    env_file: .env
    restart: always
    links:
      - mysql:dbserver
      - elasticsearch:elasticsearch
  mysql:
    image: "mysql/mysql-server:5.7"
    env_file: .env-mysql
    restart: always
  elasticsearch:
    image: "docker.elastic.co/elasticsearch/elasticsearch:7.8.0"
    env_file: .env-es
    restart: always
like image 197
β.εηοιτ.βε Avatar answered Nov 18 '25 19:11

β.εηοιτ.βε