{"record":{"id":"395c9f221330c96b","repo":"abiosoft/colima","slug":"error-restarting-docker-w","errorCode":null,"errorMessage":"error restarting docker: %w","messagePattern":"error restarting docker: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"environment/container/docker/daemon.go","lineNumber":126,"sourceCode":"\tif err != nil {\n\t\treturn err\n\t}\n\n\t// set host-gateway ip as systemd service file\n\tcontent := fmt.Sprintf(systemdUnitFileContent, ip)\n\tif err := d.guest.Write(systemdUnitFilename, []byte(content)); err != nil {\n\t\treturn fmt.Errorf(\"error creating systemd unit file: %w\", err)\n\t}\n\n\treturn nil\n}\n\nfunc (d dockerRuntime) reloadAndRestartSystemdService() error {\n\tif err := d.systemctl.DaemonReload(); err != nil {\n\t\treturn fmt.Errorf(\"error reloading systemd daemon: %w\", err)\n\t}\n\tif err := d.systemctl.Restart(\"docker.service\"); err != nil {\n\t\treturn fmt.Errorf(\"error restarting docker: %w\", err)\n\t}\n\treturn nil\n}\n\nconst systemdUnitFilename = \"/etc/systemd/system/docker.service.d/docker.conf\"\nconst systemdUnitFileContent string = `\n[Service]\nLimitNOFILE=infinity\nExecStart=\nExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --host-gateway-ip=%s\n`\n","sourceCodeStart":108,"sourceCodeEnd":138,"githubUrl":"https://github.com/abiosoft/colima/blob/c3a5f9184d83a197184f897a9f07eb3c01b3bc88/environment/container/docker/daemon.go#L108-L138","documentation":"Colima runs 'systemctl restart docker.service' inside the guest after installing the host-gateway drop-in, and the restart failed. The drop-in replaces ExecStart with dockerd -H fd:// --containerd=... --host-gateway-ip=<ip>, so a bad IP, conflicting flags with daemon.json, or a failing dockerd causes systemd to abort the restart.","triggerScenarios":"systemctl.Restart(\"docker.service\") fails: invalid --host-gateway-ip (e.g. also present in daemon.json causing duplicate flag), dockerd startup crash, cgroup/iptables issues in the guest, or port/socket conflicts.","commonSituations":"User sets 'host-gateway-ip' in ~/.colima/default/colima.yaml while the systemd drop-in adds the same flag; guest kernel/cgroup misconfiguration; leftover daemon.json with incompatible settings.","solutions":["Check guest logs: 'colima ssh -- sudo journalctl -u docker.service -n 50'","If you set host-gateway-ip in daemon config, remove it (colima manages it via the drop-in) and restart","Inspect the drop-in and daemon.json for conflicting flags: 'colima ssh -- cat /etc/systemd/system/docker.service.d/docker.conf /etc/docker/daemon.json'","Restart clean: 'colima stop && colima start'"],"exampleFix":"# ~/.colima/default/colima.yaml (before)\ndocker:\n  host-gateway-ip: 192.168.5.2 # conflicts with systemd drop-in\n# (after)\ndocker: {} # let colima derive host-gateway-ip from /etc/hosts","handlingStrategy":"validation","validationCode":"// reject user-supplied host-gateway-ip that will duplicate the systemd flag\nif v, ok := conf[\"host-gateway-ip\"]; ok {\n    if ip, ok := v.(string); ok && net.ParseIP(ip) == nil {\n        return fmt.Errorf(\"invalid host-gateway-ip '%s' in config\", ip)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := d.reloadAndRestartSystemdService(); err != nil {\n    if strings.Contains(err.Error(), \"error restarting docker\") {\n        out, _ := d.guest.RunOutput(\"journalctl\", \"-u\", \"docker.service\", \"-n\", \"20\")\n        return fmt.Errorf(\"docker restart failed, journal: %s: %w\", out, err)\n    }\n    return err\n}","preventionTips":["Do not set 'host-gateway-ip' in colima docker config — colima derives it","Keep /etc/docker/daemon.json free of flags also supplied by the drop-in","After changing docker settings, run 'colima restart' rather than editing guest files"],"tags":["docker","systemd","vm","restart"],"backgroundTag":null,"analyzedSha":"c3a5f9184d83a197184f897a9f07eb3c01b3bc88","analyzedAt":"2026-08-15T18:58:08.334Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}