abiosoft/colima · error

error creating systemd unit file: %w

Error message

error creating systemd unit file: %w

What it means

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.

Source

Thrown at environment/container/docker/daemon.go:115

	b, err := json.MarshalIndent(conf, "", "  ")
	if err != nil {
		return fmt.Errorf("error marshaling daemon.json: %w", err)
	}
	return d.guest.Write(daemonFile, b)
}

func (d dockerRuntime) addHostGateway(conf map[string]any) error {
	// get host-gateway ip from the guest
	ip, err := getHostGatewayIp(d, conf)
	if err != nil {
		return err
	}

	// set host-gateway ip as systemd service file
	content := fmt.Sprintf(systemdUnitFileContent, ip)
	if err := d.guest.Write(systemdUnitFilename, []byte(content)); err != nil {
		return fmt.Errorf("error creating systemd unit file: %w", err)
	}

	return nil
}

func (d dockerRuntime) reloadAndRestartSystemdService() error {
	if err := d.systemctl.DaemonReload(); err != nil {
		return fmt.Errorf("error reloading systemd daemon: %w", err)
	}
	if err := d.systemctl.Restart("docker.service"); err != nil {
		return fmt.Errorf("error restarting docker: %w", err)
	}
	return nil
}

const systemdUnitFilename = "/etc/systemd/system/docker.service.d/docker.conf"
const systemdUnitFileContent string = `
[Service]

View on GitHub (pinned to c3a5f9184d)

Solutions

  1. Run 'colima stop && colima start' to recreate a clean SSH session and retry provisioning
  2. Check guest disk space: 'colima ssh -- df -h /etc /var' and grow the disk if full
  3. Verify the target dir exists/writable: 'colima ssh -- sudo mkdir -p /etc/systemd/system/docker.service.d'
  4. If the VM image is custom or modified, recreate the VM: 'colima delete && colima start'
Defensive patterns

Strategy: retry

Validate before calling

// before provisioning, ensure the guest is reachable and has space
if err := guest.RunQuiet("sh", "-c", "df -k /etc | awk 'NR==2 && $4 < 10240 { exit 1 }'"); err != nil {
    return fmt.Errorf("guest low on disk before writing systemd unit: %w", err)
}

Try / catch

if err := d.addHostGateway(conf); err != nil {
    if strings.Contains(err.Error(), "error creating systemd unit file") {
        // transient guest fs/ssh issue: full stop/start re-establishes the session
        return retryAfterRestart()
    }
    return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of abiosoft/colima@c3a5f9184d (2026-08-15). Data as JSON: /api/errors/c9eed6e40cabbd98. Report an issue: GitHub.