{"record":{"id":"9c5073c23439e008","repo":"slimtoolkit/slim","slug":"startcontainer-s-incompatible-network-mode-and","errorCode":null,"errorMessage":"startContainer(%s): incompatible network_mode and networks config","messagePattern":"startContainer\\((.+?)\\): incompatible network_mode and networks config","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/app/master/compose/execution.go","lineNumber":1321,"sourceCode":"\t\t\t\tlog.Debugf(\"startContainer(): service network config - %s\", name)\n\t\t\t\tif _, ok := activeNetworks[name]; ok {\n\t\t\t\t\tnetMode = activeNetworks[name].Name\n\t\t\t\t\tnetModeKey = name\n\t\t\t\t\tlog.Debugf(\"startContainer(): found active network config - %s (netMode=%s)\", name, netMode)\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif netMode == \"\" {\n\t\t\tnetMode = \"none\"\n\t\t\tlog.Debug(\"startContainer(): default netMode to none\")\n\t\t}\n\t}\n\n\tif (netMode == \"none\" || netMode == \"host\") && len(service.Networks) > 0 {\n\t\tlog.Debugf(\"startContainer(%s): incompatible network_mode and networks config\", service.Name)\n\t\treturn \"\", fmt.Errorf(\"startContainer(%s): incompatible network_mode and networks config\", service.Name)\n\t}\n\n\tnetAliases := []string{\n\t\tservice.Name,\n\t}\n\n\tif len(service.Networks) != 0 {\n\t\tnetConfig, ok := service.Networks[netModeKey]\n\t\tif ok && netConfig != nil {\n\t\t\tnetAliases = append(netAliases, netConfig.Aliases...)\n\t\t}\n\t}\n\n\tendpointsConfig := map[string]*dockerapi.EndpointConfig{\n\t\tnetMode: {\n\t\t\tAliases: netAliases,\n\t\t},\n\t}","sourceCodeStart":1303,"sourceCodeEnd":1339,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/app/master/compose/execution.go#L1303-L1339","documentation":"startContainer validates network settings before creating the container: if the service sets network_mode to 'none' or 'host' while also defining entries under `networks:`, the configuration is contradictory (those modes bypass custom networks), so it returns 'startContainer(%s): incompatible network_mode and networks config'.","triggerScenarios":"Deploying/starting a service whose compose config has `network_mode: host` or `network_mode: none` together with a non-empty `networks:` mapping/list.","commonSituations":"Merging compose fragments where one sets network_mode: host and another adds custom networks; copying a host-networking snippet into a service that already used custom networks; override files that don't clear the networks key.","solutions":["Remove the `networks:` section from the service if host/none networking is intended","Remove or change `network_mode: host`/`none` if custom networks are required (use a bridged network instead)","Fix override/merge files so they clear conflicting keys, e.g. set networks: {} when overriding network_mode"],"exampleFix":"// before (docker-compose.yml)\n  monitor:\n    network_mode: host\n    networks:\n      - backend      # incompatible with host networking\n// after\n  monitor:\n    network_mode: host\n    # networks removed","handlingStrategy":"validation","validationCode":"func checkNetworkCompat(svc types.ServiceConfig) error {\n    if (svc.NetworkMode == \"host\" || svc.NetworkMode == \"none\") && len(svc.Networks) > 0 {\n        return fmt.Errorf(\"service %q: network_mode %q incompatible with networks %v\",\n            svc.Name, svc.NetworkMode, svc.Networks)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"_, err := execution.StartService(ctx, svcName)\nif err != nil {\n    if strings.Contains(err.Error(), \"incompatible network_mode and networks config\") {\n        return fmt.Errorf(\"fix compose file: drop networks or network_mode for %q: %w\", svcName, err)\n    }\n    return err\n}","preventionTips":["When setting network_mode: host or none, remove the networks section","Review override/merge files for conflicting network keys","Use `docker compose config` to inspect the merged final config before deploying"],"tags":["docker","compose","networking"],"backgroundTag":"incompatible-network-mode","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}