GoogleContainerTools/skaffold · error

cleaning up deployed container

Error message

cleaning up deployed container

What it means

During Cleanup, the docker deployer deletes every container recorded in its tracker via d.client.Delete. If the daemon fails to remove one (missing, in use, daemon error), the error is wrapped with "cleaning up deployed container" and cleanup aborts, leaving remaining resources behind.

Source

Thrown at pkg/skaffold/deploy/docker/deploy.go:366

	return currentName
}

func (d *Deployer) Dependencies() ([]string, error) {
	// noop since there is no deploy config
	return nil, nil
}

func (d *Deployer) Cleanup(ctx context.Context, out io.Writer, dryRun bool, _ manifest.ManifestListByConfig) error {
	if dryRun {
		for _, container := range d.tracker.DeployedContainers() {
			output.Yellow.Fprintln(out, container.ID)
		}
		return nil
	}
	for _, container := range d.tracker.DeployedContainers() {
		if err := d.client.Delete(ctx, out, container.ID); err != nil {
			// TODO(nkubala): replace with actionable error
			return errors.Wrap(err, "cleaning up deployed container")
		}
		d.portManager.RelinquishPorts(container.ID)
	}

	for _, m := range d.debugger.SupportMounts() {
		if err := d.client.VolumeRemove(ctx, m.Source); err != nil {
			return errors.Wrap(err, "cleaning up debug support volume")
		}
	}

	if err := d.client.NetworkRemove(ctx, d.network); d.networkDeployed && err != nil {
		return errors.Wrap(err, "cleaning up skaffold created network")
	}

	return d.cleanPreviousDeployments(ctx)
}

func (d *Deployer) cleanPreviousDeployments(ctx context.Context) error {

View on GitHub (pinned to a1189de023)

Solutions

  1. Run `skaffold delete` again — often the remaining containers then clean or are already gone
  2. Manually remove leftovers: `docker rm -f <container-id>` (IDs are in the tracker/daemon)
  3. Restart the Docker daemon and re-run cleanup if the daemon was down
  4. Wipe all skaffold-tagged resources: `docker ps -aq --filter label=<skaffold-label> | xargs docker rm -f`
  5. Check the wrapped inner error: a 404 usually means the container was already deleted and is safe to ignore

Example fix

// before
error: cleaning up deployed container: Error response from daemon: removal of container ... is already in progress
// after
$ docker rm -f <container-id>
$ skaffold delete  # now completes
Defensive patterns

Strategy: try-catch

Validate before calling

null

Type guard

null

Try / catch

if err := deployer.Cleanup(ctx, out); err != nil {
  if strings.Contains(err.Error(), "cleaning up deployed container") {
    log.Printf("partial cleanup: %v; continuing with manual removal", err)
    exec.Command("sh", "-c", "docker ps -aq --filter label=skaffold.dev/... | xargs -r docker rm -f").Run()
  }
  return err
}

Prevention

When it happens

Trigger: Deployer.Cleanup iterates d.tracker.DeployedContainers() and d.client.Delete(ctx, out, container.ID) returns an error — container already gone (404 on some code paths), stop timeout, or daemon unreachable.

Common situations: Container manually removed with `docker rm` before `skaffold delete`; container stuck in a non-stoppable state after a daemon crash; Docker Desktop/colima shut down before cleanup; stale tracker state from a previous failed run.

Related errors


AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05). Data as JSON: /api/errors/e80ddd1b814e9f90. Report an issue: GitHub.