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.
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.
# 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.
docker compose config | grep -A3 -E 'network_mode|networks'How to prevent it
- Choose
network_modeornetworksper service, never both. - Check that
extends/base files do not inject a conflictingnetwork_mode. - Validate with
docker compose configbeforeup.