Is there a way to override a docker-compose base file that has 'networks' defined with 'network_mode'

For example, I want a docker-compose.debug.yml file of a similar format to:

version: '3.7'
services:
  mysql:
    networks: {}
    network_mode: host
    ports:
      - 3306:3306
  memcached:
    networks: {}
    network_mode: host
    ports:
      - 11211:11211
  play-app:
    networks: {}
    network_mode: host
    ports:
      - 9000:9000

Is this possible?

Whatever I try, I get:

ERROR: 'network_mode' and 'networks' cannot be combined

Is there a way to override a service key with a null value? So that it is as if the key was not set at all?

I found a solution. Maybe it is the way this overriding feature was intended, keen to hear from other’s experience.

I took networks out of the base conf and only added it to prod.

For reference, my confs look something like this:

docker-compose.yml (base):

version: '3.7'

services:

  play-app:
    container_name: play-app
    hostname: play-app
    restart: unless-stopped
    image: openjdk:8-jre
    volumes:
      - /var/www/${APPLICATION_FQDN}/artifacts/${APPLICATION_SNAPSHOT_DIR}:/var/www/${APPLICATION_FQDN}
      - /var/www/${APPLICATION_FQDN}/deployments/conf/aws.conf:/var/www/${APPLICATION_FQDN}/deployments/conf/aws.conf
    working_dir: /var/www/${APPLICATION_FQDN}
    expose:
      - 9000
    command:
      - /var/www/${APPLICATION_FQDN}/bin/server
      - -Dconfig.file=/var/www/${APPLICATION_FQDN}/deployments/conf/live.conf
    environment:
      - APPLICATION_SECRET
      - APPLICATION_DB_ENGINE
      - APPLICATION_DB_USER
      - APPLICATION_DB_PASSWORD
      - APPLICATION_DB_SERVER
      - APPLICATION_DB_NAME
      - APPLICATION_FQDN

  memcached:
    container_name: memcached
    hostname: memcached
    image: memcached:1.5.16

docker/compose/dev.yml:

version: '3.7'

services:

  mysql:
    container_name: mysql
    hostname: mysql
    image: mysql:5.6
    restart: always
    volumes:
      - ./docker/mysql/create_databases.sql:/docker-entrypoint-initdb.d/1_create_databases.sql
      - mysql:/var/lib/mysql
    command:
      - --default-authentication-plugin=mysql_native_password
    environment:
      MYSQL_ROOT_PASSWORD: root
    network_mode: host
    ports:
      - 3306:3306

  memcached:
    network_mode: host
    ports:
      - 11211:11211

  play-app:
    command:
      - /var/www/${APPLICATION_FQDN}/bin/server
      - -Dliquibase.apply=true
      - -Ddb.default.password=${APPLICATION_DB_PASSWORD}
      - -Dhttp.port=9002
      - -Dsecuresocial.ssl=true
      - -Ddomain=app.local
      - -Dconfig.resource=local.conf
      - -Dpidfile.path=/dev/null
    network_mode: host
    ports:
      - 9002:9002
    depends_on:
      - mysql

volumes:
  mysql:

docker/compose/prod.yml:

version: '3.7'
services:
  caddy:
    container_name: caddy
    hostname: caddy
    restart: unless-stopped
    image: abiosoft/caddy:1.0.0
    depends_on:
      - play-app
    volumes:
      - /var/www/${APPLICATION_FQDN}/caddy/Caddyfile:/etc/Caddyfile
      - /var/www/${APPLICATION_FQDN}/artifacts/caddy/.caddy:/root/.caddy
      - /var/www/${APPLICATION_FQDN}/artifacts/caddy/logs:/var/log/caddy
      - /var/www/${APPLICATION_FQDN}/artifacts/${APPLICATION_SNAPSHOT_DIR}:/var/www/${APPLICATION_FQDN}
    environment:
      ACME_AGREE: 'true'
    networks:
      - main
    ports:
      - 80:80
      - 443:443

  memcached:
    networks:
      - main

  play-app:
    networks:
      - main

networks:

  main:

Then to show full dev config:
docker-compose -f docker-compose.yml -f docker/compose/dev.yml config

Then to show full prod config:
docker-compose -f docker-compose.yml -f docker/compose/prod.yml config