bcicen/ctop · error

cannot inspect container: %v

Error message

cannot inspect container: %v

What it means

Docker.Start inspects the container by ID before starting it. If InspectContainer fails (container doesn't exist, Docker daemon unreachable, API error), Start aborts with 'cannot inspect container: <cause>'.

Source

Thrown at connector/manager/docker.go:108

		Tty:          true,
	})

	if err != nil {
		return err
	}

	return dc.client.StartExec(execCmd.ID, api.StartExecOptions{
		InputStream:  &noClosableReader{os.Stdin},
		OutputStream: &frameWriter{os.Stdout, os.Stderr, os.Stdin},
		ErrorStream:  os.Stderr,
		RawTerminal:  true,
	})
}

func (dc *Docker) Start() error {
	c, err := dc.client.InspectContainer(dc.id)
	if err != nil {
		return fmt.Errorf("cannot inspect container: %v", err)
	}

	if err := dc.client.StartContainer(c.ID, c.HostConfig); err != nil {
		return fmt.Errorf("cannot start container: %v", err)
	}
	return nil
}

func (dc *Docker) Stop() error {
	if err := dc.client.StopContainer(dc.id, 3); err != nil {
		return fmt.Errorf("cannot stop container: %v", err)
	}
	return nil
}

func (dc *Docker) Remove() error {
	if err := dc.client.RemoveContainer(api.RemoveContainerOptions{ID: dc.id}); err != nil {
		return fmt.Errorf("cannot remove container: %v", err)

View on GitHub (pinned to 59f00dd6aa)

Solutions

  1. Verify the container exists (docker inspect <id>) and recreate it if removed
  2. Check Docker daemon reachability and DOCKER_HOST configuration
  3. Check permissions on /var/run/docker.sock or remote TLS settings
  4. Refresh the stored container id after daemon/host restarts

Example fix

// before
dc := &manager.Docker{ID: staleID}
dc.Start() // cannot inspect container: No such container
// after
c, err := dc.Inspect(); if err != nil { c, err = dc.Create() }
err = dc.Start()
Defensive patterns

Strategy: try-catch

Validate before calling

if _, err := dc.client.InspectContainer(dc.id); err != nil { /* recreate container before Start */ }

Type guard

func containerExists(dc *manager.Docker) bool { _, err := dc.client.InspectContainer(dc.id); return err == nil }

Try / catch

if err := dc.Start(); err != nil {
    if strings.HasPrefix(err.Error(), "cannot inspect container") {
        // recreate container or check daemon connectivity
    }
}

Prevention

When it happens

Trigger: Calling Docker.Start() with an id referencing a removed/nonexistent container, or when the Docker daemon/remote API is unreachable or returns an error.

Common situations: Container was removed between creation and start; DOCKER_HOST misconfigured or daemon down; stale container id cached after a restart; insufficient permissions on the Docker socket.

Related errors


AI-assisted analysis of bcicen/ctop@59f00dd6aa (2026-09-02). Data as JSON: /api/errors/e931723e38758c51. Report an issue: GitHub.