Skip to content
Latchkey

Docker Compose "network_mode and networks cannot be combined" in CI

Compose rejected a service because it sets both network_mode and networks. These are mutually exclusive - network_mode (host/none/container:/service:) takes over networking entirely, so a networks list cannot also apply.

What this error means

A docker compose up/config fails during validation with service "<x>" declares mutually exclusive network_mode and networks. Nothing starts because the network configuration is contradictory.

docker compose output
services.api: conflicting parameters "network_mode" and "networks" specified
# the service has both:
#   network_mode: host
#   networks: [backend]

Common causes

network_mode used with a networks list

network_mode: host (or container:/service:/none) fully defines the container’s networking. Adding a networks: list contradicts it, so Compose refuses the service.

Inherited network_mode from an extends/base file

A base service (via extends) sets network_mode while the concrete service adds networks, producing the conflict after merge.

How to fix it

Pick one networking model

Use either network_mode or networks, not both.

docker-compose.yml
# host networking - no networks list:
services:
  api:
    network_mode: host
# OR custom networks - no network_mode:
services:
  api:
    networks: [backend]
networks:
  backend:

Reconcile merged config from extends

Render the merged config to find where both keys end up set.

Terminal
docker compose config | grep -A3 -E 'network_mode|networks'

How to prevent it

  • Choose network_mode or networks per service, never both.
  • Check that extends/base files do not inject a conflicting network_mode.
  • Validate with docker compose config before up.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →