abiosoft/colima · error

error restarting docker: %w

Error message

error restarting docker: %w

What it means

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.

Source

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

	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]
LimitNOFILE=infinity
ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --host-gateway-ip=%s
`

View on GitHub (pinned to c3a5f9184d)

Solutions

  1. Check guest logs: 'colima ssh -- sudo journalctl -u docker.service -n 50'
  2. If you set host-gateway-ip in daemon config, remove it (colima manages it via the drop-in) and restart
  3. 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'
  4. Restart clean: 'colima stop && colima start'

Example fix

# ~/.colima/default/colima.yaml (before)
docker:
  host-gateway-ip: 192.168.5.2 # conflicts with systemd drop-in
# (after)
docker: {} # let colima derive host-gateway-ip from /etc/hosts
Defensive patterns

Strategy: validation

Validate before calling

// reject user-supplied host-gateway-ip that will duplicate the systemd flag
if v, ok := conf["host-gateway-ip"]; ok {
    if ip, ok := v.(string); ok && net.ParseIP(ip) == nil {
        return fmt.Errorf("invalid host-gateway-ip '%s' in config", ip)
    }
}

Try / catch

if err := d.reloadAndRestartSystemdService(); err != nil {
    if strings.Contains(err.Error(), "error restarting docker") {
        out, _ := d.guest.RunOutput("journalctl", "-u", "docker.service", "-n", "20")
        return fmt.Errorf("docker restart failed, journal: %s: %w", out, err)
    }
    return err
}

Prevention

When it happens

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

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

Related errors


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