{"record":{"id":"c9eed6e40cabbd98","repo":"abiosoft/colima","slug":"error-creating-systemd-unit-file-w","errorCode":null,"errorMessage":"error creating systemd unit file: %w","messagePattern":"error creating systemd unit file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"environment/container/docker/daemon.go","lineNumber":115,"sourceCode":"\n\tb, err := json.MarshalIndent(conf, \"\", \"  \")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error marshaling daemon.json: %w\", err)\n\t}\n\treturn d.guest.Write(daemonFile, b)\n}\n\nfunc (d dockerRuntime) addHostGateway(conf map[string]any) error {\n\t// get host-gateway ip from the guest\n\tip, err := getHostGatewayIp(d, conf)\n\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]","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/abiosoft/colima/blob/c3a5f9184d83a197184f897a9f07eb3c01b3bc88/environment/container/docker/daemon.go#L97-L133","documentation":"Colima fails to write the docker.service systemd drop-in (/etc/systemd/system/docker.service.d/docker.conf) that injects the --host-gateway-ip flag into the guest VM. The write goes through the guest (SSH) filesystem layer, so the wrapped error usually originates there. It is part of addHostGateway, which runs during docker runtime provisioning.","triggerScenarios":"guest.Write() of the rendered systemdUnitFileContent fails: SSH/session to the Lima VM is broken, guest disk is full, /etc/systemd/system/docker.service.d/ is unwritable, or the VM was stopped mid-provision.","commonSituations":"colima start after an interrupted previous start, a full or corrupted VM disk, custom VM images where /etc is read-only, or sshd in the guest not accepting the control-socket connection.","solutions":["Run 'colima stop && colima start' to recreate a clean SSH session and retry provisioning","Check guest disk space: 'colima ssh -- df -h /etc /var' and grow the disk if full","Verify the target dir exists/writable: 'colima ssh -- sudo mkdir -p /etc/systemd/system/docker.service.d'","If the VM image is custom or modified, recreate the VM: 'colima delete && colima start'"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// before provisioning, ensure the guest is reachable and has space\nif err := guest.RunQuiet(\"sh\", \"-c\", \"df -k /etc | awk 'NR==2 && $4 < 10240 { exit 1 }'\"); err != nil {\n    return fmt.Errorf(\"guest low on disk before writing systemd unit: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := d.addHostGateway(conf); err != nil {\n    if strings.Contains(err.Error(), \"error creating systemd unit file\") {\n        // transient guest fs/ssh issue: full stop/start re-establishes the session\n        return retryAfterRestart()\n    }\n    return err\n}","preventionTips":["Always stop colima cleanly ('colima stop') before shutting down the host to keep the guest FS consistent","Keep guest disk usage monitored; grow with 'colima start --disk' before it fills","Avoid custom guest images that make /etc read-only"],"tags":["docker","systemd","vm","ssh","provisioning"],"backgroundTag":null,"analyzedSha":"c3a5f9184d83a197184f897a9f07eb3c01b3bc88","analyzedAt":"2026-08-15T18:58:08.334Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}